你好我正在项目中使用SDWebImage框架,我想下载和缓存图像,但我认为我的代码是在缓存中存储两次图像?有没有办法通过一个键将图像存储在缓存中一次?这是我的代码。SDWebImage下载图像并存储到缓存的密钥
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:[NSURL URLWithString:url] options:0 progress:^(NSUInteger receivedSize, long long expectedSize) {
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
if(image){
NSString *localKey = [NSString stringWithFormat:@"Item-%d", i];
[[SDImageCache sharedImageCache] storeImage:image forKey:localKey];
}
}];
有什么我错过了吗?看起来在我的分配工具中这样做会占用大量内存。
你的意思是,如果我们为每一个(固定下载图像URL)键,它会不会开除下载事件在网络上?对 ? 它会使用先前的缓存吗? – 2013-11-28 07:09:42
自从我看了这个以后,过了一段时间,但如果您计划使用特定的缓存键存储图像,则在进行下载请求之前,应检查图像的[[SDImageCache sharedImageCache]]。如果您没有它,请使用您的特定密钥进行存储,以便下次使用。现在这可能已经改变了,但是如果你要这样做,你应该使用'SDWebImageDownloader',然后存储你自己的密钥。 – Stakenborg 2013-12-02 14:50:39