Wednesday, November 27, 2013

SDWebImage clearing cache http://stackoverflow.com/questions/13865537/sdwebimage-clearing-cache

http://stackoverflow.com/questions/13865537/sdwebimage-clearing-cache

SDWebImage clearing cache


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?

asked Dec 13 '12 at 17:50
Eugene
4,8241921
add comment

3 Answers

  SDImageCache *imageCache = [SDImageCache sharedImageCache];  [imageCache clearMemory];  [imageCache clearDisk];  [imageCache cleanDisk];

Don't forget to put these lines of code in your didReceiveMemoryWarning, too.

answered Apr 29 at 11:23
proca 2.0
46659
 
The current version of SDWebImage will automatically clear the memory cache when memory warnings occur. No need to do this and especially no need to clear disk cache. –  TomA Jun 28 at 14:36
 
can you please add a source. Which version will support these functionality exactly? –  proca 2.0 Jun 28 at 15:34
1  
add comment

Located the source if an issue. It seems that I was deceived by the Singleton pattern used inSDImageCache. The cache for extension that is used over UIImageView is being controlled bySDWebImageManager 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.

answered Dec 14 '12 at 15:31
Eugene
4,8241921
 
not able to call clearcache method. [[SDWebImageManager sharedManager] clearCaches] . i tried this but it is crashing. please help me. –  Suraj Shinde May 31 at 15:33 
 
@SurajShinde There's no such method for SDImageCache, of course it will crash. Use[[[SDWebImageManager sharedManager] imageCache] clearDisk];,[[[SDWebImageManager sharedManager] imageCache] clearMemory]; –  Eugene May 31 at 18:24
 
Thanks, Actully i was using old SDwebcache it did not have imageCache instance. –  Suraj Shinde Jun 1 at 19:11
add comment

Did u try the following:

  [[SDImageCache sharedImageCache]release];

also have a look at: here and here

No comments:

Post a Comment