AlamofireImage:如何清除所有图像缓存?

Kri*_*ish 2 caching uiimage ios alamofireimage swift3

如何使用AlamofireImage从缓存中清除所有图像。我经历了以下答案(发布在堆栈溢出中),但是它们都不起作用。

如何清除AlamofireImage setImageWithURL缓存
AlamofireImage缓存?
AlamofireImage如何清理内存和缓存


我尝试清除缓存的代码:

UIImageView.af_sharedImageDownloader.imageCache?.removeAllImages()
Run Code Online (Sandbox Code Playgroud)

我也尝试过这个:

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()
Run Code Online (Sandbox Code Playgroud)

但是它不能从缓存中删除所有图像。

注意:我使用AlamofireImage 3.1加载图像。

Raf*_*nço 7

我遇到了同样的问题,部分解决方案对我有用:

UIImageView.af_sharedImageDownloader.imageCache?.removeAllImages()
UIImageView.af_sharedImageDownloader.sessionManager.session.configuration.urlCache?.removeAllCachedResponses()
Run Code Online (Sandbox Code Playgroud)

让我知道它是否对您也有用。

在豆荚里,我只是放

pod 'AlamofireImage'