ios - 在 v5 中将预取图像复制到内存 (SDWebImageCacheMemoryOnly)
问题描述
使用 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)};
推荐阅读
- javascript - 在函数中插入警报
- optimization - 我想使用 16 比 1 MUX 将二进制代码转换为格雷码
- proxy - WSO2 集成工作室 - 无法配置代理
- javascript - Javascript FileReader 和文件同步
- json - 清单:行:1,列:1,语法错误
- django - 认证后登录页面
- java - 箭头 (->) 运算符优先级/优先级最低,还是赋值/组合赋值的优先级最低?
- python - 如何从python中的字符中删除字符串?
- javascript - 在 AR.JS 中识别标记后重定向用户
- python - 将非常大的 csv 文件拆分为较小的文件