How to save image permanently by using sdwebimage?

时间:2018-02-05 12:55:13

标签: swift sdwebimage

I'm the new on swift. I have a question how to save image from url into permanent cache. Since URL live for only 30min and is expired after 30min, I'm using sdwebimage and saving image in disk and memory cache. My code is like the below. and it's working well. Problem is that sometimes image is not loaded because of unknown issue. I guessed that image is not saved permanently in cache..This is just my guess. So, I'd like to save image permanent cache. How can I do this? Or Is there anyone know why this symptom is observed?

My code :

cell.imageView.sd_setImage(with: URL(string: url), placeholderImage: nil)

1 个答案:

答案 0 :(得分:0)

我想当你保存它时不应该发生,也许你在项目的某个地方刷新它。

条件1:您可以设置刷新缓存代码。

imgView.sd_setImage(with: URL(string: yourString!), placeholderImage:UIImage(named: "placeholder_icon"), options: .refreshCached)

SDImageCache.shared().clearMemory()
SDImageCache.shared().clearDisk()

条件2:您可以设置刷新缓存时间,如

SDImageCache.shared().config.maxCacheAge = 60 * 60 * 24;
  
    

如果您的案件不是来自上述两个条件,我很想知道答案。