4

I am using SDWebImage for loading a list of images and it was really good but while loading images next time it's loading image from cache if the url is same. But I need to know its coming form cache or web. Any help would be greatly appreciated.

Dilip Manek
  • 9,095
  • 5
  • 44
  • 56

3 Answers3

2

Check SDWebImageManager, it has 2 versions of functions to check whether an URL is already cached or not:

- (BOOL)diskImageExistsForURL:(NSURL *)url;

There's also a version with a block which executes after the check. Hope this helps!

alasker
  • 309
  • 5
  • 18
2

You can check the cache to see if the image in question has already been downloaded like so:

NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:URL];
UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
Ric Santos
  • 15,419
  • 6
  • 50
  • 75
0

use your url

SDWebImageManager *manager = [SDWebImageManager sharedManager];
UIImage *cachedImage = [manager imageWithURL:url];

if (cachedImage) 
{
   [button setImage:cachedImage];
   //image is cashed
}
else 
{
   [manager downloadWithURL:url delegate:self];
}

and then implement delegate function

- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage*)image {
   [button setImage:image];
   // new image
}
aBilal17
  • 2,974
  • 2
  • 17
  • 23