在使用SDWebImage v4时,可以设置选项以仅通过内存缓存图像
SDWebImagePrefetcher.sharedImagePrefetcher.options = SDWebImageCacheMemoryOnly;
这似乎不再是v5的一个选项,因此这个问题。默认情况下,缓存的图像似乎来自光盘。 (有些图像出现在屏幕上有延迟,我之前通过在内存中预取它们来解决这个问题)。
我在迁移指南中看到v5现在拆分光盘和内存缓存,但我无法弄清楚如何告诉预取器只将图像存储在内存中。
来自其中一位图书馆维护者的回答,原文可以在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)};