简体   繁体   English

在v5中将预取映像复制到内存(SDWebImageCacheMemoryOnly)

[英]Replicate Prefetching images into memory (SDWebImageCacheMemoryOnly) in v5

While using SDWebImage v4 it was possible to set options to cache images in memory only via 使用SDWebImage v4时,可以设置选项以仅通过以下方式将图像缓存在内存中

SDWebImagePrefetcher.sharedImagePrefetcher.options = SDWebImageCacheMemoryOnly;

This no longer seems to be an option with v5, hence this question. 这似乎不再是v5的选项,因此是这个问题。 By default it seems that cached images are coming from disc. 默认情况下,似乎缓存的图像来自光盘。 (Some images appear on screen with delay, which I previously solved by prefetching them in memory). (某些图像会延迟显示在屏幕上,我之前通过在内存中预取来解决了这些问题)。

I saw in migration guide that v5 now splits disc and memory cache, but I am not able to figure out how to tell prefetcher to store images in memory only. 我在迁移指南中看到,v5现在可以拆分磁盘和内存缓存,但是我无法弄清楚如何告诉预取器仅将图像存储在内存中。

Answer from one of the library maintainers, original can be found at https://github.com/SDWebImage/SDWebImage/issues/2698 来自库维护者之一的答案,原始内容可以在https://github.com/SDWebImage/SDWebImage/issues/2698找到。

There is a context option called storeCacheType, the value type is SDImageCacheType. 有一个名为storeCacheType的上下文选项,值类型为SDImageCacheType。 See the documentation about it. 请参阅有关文档。

/**
 A SDImageCacheType raw value which specify the cache type when the image has just been downloaded and will be stored to the cache. Specify `SDImageCacheTypeNone` to disable cache storage; `SDImageCacheTypeDisk` to store in disk cache only; `SDImageCacheTypeMemory` to store in memory only. And `SDImageCacheTypeAll` to store in both memory cache and disk cache.
 If not provide or the value is invalid, we will use `SDImageCacheTypeAll`. (NSNumber)
 */
FOUNDATION_EXPORT SDWebImageContextOption _Nonnull const SDWebImageContextStoreCacheType;

So. 所以。 You just need to control your prefetcher, to use the SDImageCacheTypeMemory enum for this store cache type control. 您只需要控制您的预取程序,即可将SDImageCacheTypeMemory枚举用于此存储高速缓存类型控件。

SDWebImagePrefetcher.sharedImagePrefetcher.context = @{SDWebImageContextStoreCacheType : @(SDImageCacheTypeMemory)};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM