I use SDWebImage
in my app to load and cache images from the web. It works like a charm, but the only issue is that whenever I exit my app, even momentarily, the image cache gets cleared and all the images have to be downloaded again. This is especially a problem when the Internet connection is slow. I would like the images to be retained when I return to the app. Does anyone know how to achieve this?
SDWebImage - avoid clearing image cache on entering background
2.1k views Asked by Rameez Hussain At
2
There are 2 answers
0
On
make sure you don't set the maxCacheSize
of [SDImageCache sharedImageCache]
, if it is set when the app go to background, it will clear cache files to fit the maxCacheSize
.
in cleanDisk
method, you can see there is a check before removing files
if (self.maxCacheSize > 0 && currentCacheSize > self.maxCacheSize)
{
// ...
}
so if maxCacheSize
is not set, it will do nothing.
Go to SDImageCache.m and seek method - (id)initWithNamespace:(NSString *)ns There you will find such code:
Feel free to comment out or change anything if you want. I'd make an option to turn off these lines of code.