darkginger
darkginger

Reputation: 690

Clearing cache in SDWebImage for iOS app

Facepalm. I have been using a Github image downloader to display remote images. This is SDWebImage. I've been playing with this for an hour and a half and I'm totally lost apparently and would be eternally grateful if someone could help me figure this out.

So basically, in the SDImageCache.h file of the framework, it it set to cache images for a week. That is problematic if you are trying to update your images frequently, since it doesn't download if the image is already cached.

On Stack Overflow, I've found a bunch of people with the same issue, but so far, the solutions haven't worked. Luckily, the guy who came up with this posted his solution to empty the image cache: call for "[SDWebImageManager.sharedManager.imageCache clearMemory]".

I put that method in my main view controller's .m file with the hope it would clear the cache after calling for the image so it would update. No dice. I tried it before the ViewDidLoad too with the hope it would clear the image and initiate a download. No luck again.

Any advice on what I'm doing wrong? Here's a screen shot of my implementation file if that helps! This is driving me nuts. Thanks!

https://i.sstatic.net/ckXCj.png

Upvotes: 0

Views: 1563

Answers (2)

Velociround
Velociround

Reputation: 631

I don't know about back in 2012 or 2013, but today you can simply call passing the options you want, for example SDWebImageRefreshCached (respects HTTP header and refreshes the image, even if it is already cached or using the same URL) or SDWebImageCacheMemoryOnly (does not cache to disk, only to memory)

Example:

NSString *string = @"http://example.com/image.jpg";
[self.customImageView setImageWithURL:[NSURL URLWithString:string]
                     placeholderImage:nil
                              options:SDWebImageRefreshCached
                             progress:nil
                            completed:nil]

Upvotes: 0

darkginger
darkginger

Reputation: 690

Just following up in case anyone finds this searching. To correct the problem, what you want to do is make sure the full SDWebImage package is moved into your framework folder.

At that point, you can find a WebImageCache.m file and tailor it to your specific cache needs.

Additionally, if you look in the same project on the Github, you can actually install a "clear cache" bar that uses the SDWebImageManager to enable the user to clear the cache. In my particular instance, that was very useful.

Good luck!

Upvotes: 1

Related Questions