If you're using AFNetworking, I recently implemented a little workaround to remove the image from the cache.
Look in the file "UIImageView+AFNetworking.h"
Under @interface UIImageView (AFNetworking)
, add the following:
- (void)clearImageCacheForURL:(NSURL *)url;
And Under @protocol AFImageCache
, add:
- (void)clearCachedRequest:(NSURLRequest *)request;
Next, open "UIImageView+AFNetworking.m"
Under @implementation UIImageView (AFNetworking)
, add the following:
- (void)clearImageCacheForURL:(NSURL *)url {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
UIImage *cachedImage = [[[self class] sharedImageCache] cachedImageForRequest:request];
if (cachedImage) {
[[[self class] sharedImageCache] clearCachedRequest:request];
}
}
Almost done! Now just add the following below @implementation AFImageCache
:
- (void)clearCachedRequest:(NSURLRequest *)request {
if (request) {
[self removeObjectForKey:AFImageCacheKeyFromURLRequest(request)];
}
}
And you're good to go! Now when you need to clear a particular image url from the cache, just call [imageView clearImageCacheForURL:imgURL];