Alamofire图像caching?

我将AlamofireImagePromiseKitAlamofire结合使用。 我使用承诺来链接x数量的图像下载,因为我想这样做同步。 我似乎无法理解,如果ImageDownloader()自动caching,或者如果我必须明确地将图像添加到caching? 我目前看到的唯一例子是没有使用ImageDownloader所以我很难find答案。

如果没有 – 我如何添加caching? 我试过使用:

 self.imageDownloader.imageCache?.addImage(image, withIdentifier: imageUrl) 

但是它所做的只是增加我所有永恒的内存使用量(例如,一次又一次地将相同的图像添加到caching中)

我认为定义一个AutoPurgingImageCache()然后在caching过程中使用它需要解决你的内存使用问题。

 let photoCache = AutoPurgingImageCache( memoryCapacity: 100 * 1024 * 1024, preferredMemoryUsageAfterPurge: 60 * 1024 * 1024 ) 

你可以改变memoryCapacitypreferredMemoryUsageAfterPurge表示MB。 要在caching中添加任何图像,可以这样使用:

 photoCache.addImage(scaledImage, withIdentifier: urlString) 

你也可以检查这个主题的更多细节和AlamofireImage GitHub页面。