SDWebImage clearing cache SDWebImage clearing cache ios ios

SDWebImage clearing cache


SDImageCache *imageCache = [SDImageCache sharedImageCache];[imageCache clearMemory];[imageCache clearDisk];

Don't forget to put these lines of code in your didReceiveMemoryWarning, too.


Located the source if an issue. It seems that I was deceived by the Singleton pattern used in SDImageCache. The cache for extension that is used over UIImageView is being controlled by SDWebImageManager which has an instance variable of SDImageCache. If you want to clear the cache for extension you have to call its imageCache's methods like clearDisk and clearMemory.


Only following code worked for me : Swift 5.0, Xcode 11, iOS 13, SDWebImage pod 5.0

 SDWebImageManager.shared.imageCache.clear(with: .all) {        print("deleted all") }

where you choose options like SDImageCacheType.disk, SDImageCacheType.memory, SDImageCacheType.disk

Also if you want to remove specific image from cache use following:

SDWebImageManager.shared.imageCache.removeImage(forKey: "url of image", cacheType: .all)


matomo