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

时间:2019-04-18 15:54:14

标签: ios image caching sdwebimage

使用SDWebImage v4时,可以设置选项以仅通过以下方式将图像缓存在内存中

SDWebImagePrefetcher.sharedImagePrefetcher.options = SDWebImageCacheMemoryOnly;

这似乎不再是v5的选项,因此是这个问题。默认情况下,似乎缓存的图像来自光盘。 (有些图像会延迟显示在屏幕上,我之前是通过在内存中预取来解决的。)

我在迁移指南中看到,v5现在可以拆分磁盘和内存缓存,但是我无法弄清楚如何告诉预取器仅将图像存储在内存中。

1 个答案:

答案 0 :(得分:0)

其中一位图书馆维护者的答案是,可以在https://github.com/SDWebImage/SDWebImage/issues/2698

找到原始文件

有一个名为storeCacheType的上下文选项,值类型为SDImageCacheType。请参阅有关文档。

/**
 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;

所以。您只需要控制预取程序,即可将SDImageCacheTypeMemory枚举用于此存储缓存类型控件。

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