I'm displaying a list of icons downloaded from the web with text in a table view. The icons can be changed on server side and I need to replace them as soon as new icons are getting available. I try using the following code:
[imgView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"table_avatar_icon"] options:SDWebImageCacheMemoryOnly];
And call [[SDImageCache sharedImageCache] clearMemory];
In my refresh callback, but it does not purge the contents of the cache. More to it, even if I close the application and open it again the image is still there.
I found only one way to clear the cache and it is by calling [[SDImageCache sharedImageCache] clearDisk];
. Which only works after I close and reopen the app.
How can I force SDWebImage to not to use disk caching?
SDImageCache *imageCache = [SDImageCache sharedImageCache]; [imageCache clearMemory]; [imageCache clearDisk];
Don't forget to put these lines of code in your didReceiveMemoryWarning
, too.
Located the source if an issue. It seems that I was deceived by the Singleton pattern used in SDImageCache
. The cache for extension that is used over UIImageView is being controlled by SDWebImageManager
which has an instance variable of SDImageCache
. If you want to clear the cache for extension you have to call its imageCache
's methods like clearDisk and clearMemory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With