SDImageCache 无法检索缓存中保存的图像
SDImageCache unable to retrieve the saved images in Cache
我正在使用 SDWebImage 使用密钥将图像存储在缓存和磁盘内存中,但是在使用该密钥进行查询时我没有获取图像,代码是
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");
}
试试这个
.
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");
}
我正在使用 SDWebImage 使用密钥将图像存储在缓存和磁盘内存中,但是在使用该密钥进行查询时我没有获取图像,代码是
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");
}
试试这个 .
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");
}