Reputation: 59
How to clear all images from cache using AlamofireImage. I’ve gone through following answers (posted in stack overflow) but none of them working.
How to clear AlamofireImage setImageWithURL cache
AlamofireImage cache?
AlamofireImage how to clean memory and cache
Code I’ve tried to clear cache:
UIImageView.af_sharedImageDownloader.imageCache?.removeAllImages()
I tried this also:
let sharedCache = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
URLCache.shared = sharedCache
//Clear all cookies
if let sharedCookies = HTTPCookieStorage.shared.cookies {
for cookie in sharedCookies {
HTTPCookieStorage.shared.deleteCookie(cookie)
}
}
//-----------------------------------
URLCache.shared.removeAllCachedResponses()
But it can’t remove all images from cache.
Note: I’ve used AlamofireImage 3.1 to load images.
Upvotes: 2
Views: 1634
Reputation: 1166
I had the same problem and part of your solution worked for me:
UIImageView.af_sharedImageDownloader.imageCache?.removeAllImages()
UIImageView.af_sharedImageDownloader.sessionManager.session.configuration.urlCache?.removeAllCachedResponses()
Let me know if it worked for you too.
In pods, I just put
pod 'AlamofireImage'
Upvotes: 8