代码之家  ›  专栏  ›  技术社区  ›  Ilja

关闭应用程序后未保留预取的SDWebImage

  •  0
  • Ilja  · 技术社区  · 7 年前

    我正在使用 SDWebImage 预取IE

    SDWebImagePrefetcher
          .shared()
          .prefetchURLs(
            urls as [URL],
            progress: nil,
            completed: { finished, skipped in
              onComplete([finished, skipped])
            }
          )
    

    一切看起来都很好,当我使用我的应用程序时,所有期望的图像都会被缓存并感觉到响应。我正在展示一个加载程序,同时获取这些图像,大约需要4-5秒完成。

    我希望下次打开我的应用程序时,此预取将是即时的,因为图像应该已经在缓存中了?但是,如果我完全退出我的应用程序(从iOS的活动应用程序视图中关闭它等等),然后再打开它,我必须再次等待同样的4-5秒。

    我是不是错过了理解这个方法的作用,也许还有另一个解决方案可以表现出我所期望的效果?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Mosbah    7 年前

    尝试将缓存类型从以下源强制到磁盘:

    /**
     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)
     */
    SDWebImageContextOption _Nonnull const SDWebImageContextStoreCacheType;
    

    链接在这里: https://github.com/SDWebImage/SDWebImage/blob/5.x/SDWebImage/SDWebImageDefine.h#L204-L208