Reputation: 2626
I am using the SDWebImage
to load the image from URL. When image is updated on the server, then image is not updating in the image view even i have used options: .refreshCached
. After updating image, URL remains same.
Can i directly change image in cache for this URL?
I googled for this question,i got that i can not change it in cache directly. If i can not change image in cache directly for specify URL, Is it possible to clear cached value for specific key (URL)?
self.imgView.sd_setImage(with: url, placeholderImage: #imageLiteral(resourceName: "Timg"), options: .refreshCached, completed: { (image: UIImage?, error: Error?, cacheType: SDImageCacheType, imageURL: URL?) in
if image != nil{
self.imgView.contentMode = .scaleAspectFill
}
})
Upvotes: 0
Views: 1154
Reputation: 20379
Looks like the issue has already been raised in the official GitHub page of SDWebImage. Clearly the answer suggests that [[SDImageCache sharedImageCache] removeImageForKey:image_url fromDisk:YES];
is not doing fair enough job to clear the image.
Suggested answer says
[[SDImageCache sharedImageCache] clearMemory];
[[SDImageCache sharedImageCache] cleanDisk];
Now whether you need both the statements or not depends on how you have configured SDImageCache.
What do they mean ?
SDWebImage caches images extensively, it keeps the copy of cache in RAM as well as in HardDisk. When an image is requested, it hits the RAM Cache first to find the image, if not found then hits disk cache. And loads RAM cache from disk cache.
So clearing simply from disk will still leave image in Disk cache and when requested an image rather than downloading from web it rather loads from Disk and keeps a copy in RAM for future use. So it defeats the idea of deleting the image from cache.
I know its not the answer you are specifically looking for, but unfortunately am not aware of deleting specific image from SDImageCache.
Upvotes: 3
Reputation:
[[SDImageCache sharedImageCache] removeImageForKey:image_url fromDisk:YES];
Upvotes: 2