-1

I'm using SDWebImage to store the images in cache and disk memory using a key but while querying using that key i am not getting the images, the code is

 SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"ImageCacheFolder"];
[imageCache queryCacheOperationForKey:[entryidarray objectAtIndex:indexpath.row] done:^(UIImage *image, NSData *data, SDImageCacheType cacheType) {
    if (image) {
        NSLog(@"image get from cache");
        [imageview setImage:image];
    } else {
        [imageview sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:@"PlaceholderImage-Day"] options:SDWebImageProgressiveDownload];
    } 
}];

NSURL *url = [NSURL URLWithString:imgStr];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];

if (img) {
    NSLog(@"the image is not nil");
    [[SDImageCache sharedImageCache] storeImage:img forKey:[entryidarray objectAtIndex:indexpath.row] toDisk:YES completion:nil];
}else {
    NSLog(@"the image is nil");
}
R. Mohan
  • 2,182
  • 17
  • 30

1 Answers1

2

Try this .

if (img) {
    NSLog(@"the image is not nil");
    [imageCache storeImage:img forKey:[entryidarray objectAtIndex:indexpath.row] toDisk:YES completion:nil];
}else {
    NSLog(@"the image is nil");
}
KKRocks
  • 8,222
  • 1
  • 18
  • 84