How to save image permanently by using sdwebimage?

2019-08-27 16:32发布

问题:

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:

I guess it should not happen when you are saving it already, maybe you are refreshing it somewhere in your project.

Condition 1: May you have set the refresh cache code.

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

or

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

Condition 2: May you have set the refresh cache time like

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

If your case is not from above two conditions, I am eager to know the answer.