我将 AlamofireImage 与 PromiseKit 和 Alamofire 。由于我想同步执行此操作,因此我使用promise来链接x个图像的下载。我似乎无法理解 ImageDownloader()是自动缓存还是必须将图像显式添加到缓存?到目前为止,我所看到的唯一示例都没有使用 ImageDownloader ,因此我很难找到答案。
I use AlamofireImage in conjunction with PromiseKit and Alamofire. I use promises to chain the download of x number of images since I want to do this synchronically. I can't seem to understand if ImageDownloader() caches automatically or if I have to add the image explicitly to the cache? The only examples I've seen so far are not using the ImageDownloader so I have a real hard time finding an answer to this.
如果没有-如何添加缓存?我试过使用:
If not - how do I add it the cache? I've tried using:
self.imageDownloader.imageCache?.addImage(image, withIdentifier: imageUrl)但是它所做的就是增加我所有永恒的内存使用(即一遍又一遍地向缓存中添加相同的图像)
But all it does is increase my memory usage for all eternity(i.e. adding the same image to the cache over and over)
推荐答案我认为定义AutoPurgingImageCache()并在缓存过程中使用它需要解决您的内存使用问题。
I think that defining an AutoPurgingImageCache() and then using it while caching process need to solve your memory usage problem.
let photoCache = AutoPurgingImageCache( memoryCapacity: 100 * 1024 * 1024, preferredMemoryUsageAfterPurge: 60 * 1024 * 1024 )您可以更改 memoryCapacity , preferredMemoryUsageAfterPurge 代表MB。要在缓存中添加任何图像,可以这样使用:
You can change memoryCapacity, preferredMemoryUsageAfterPurge represent MB. To add any image in your cache, you can use like that:
photoCache.addImage(scaledImage, withIdentifier: urlString)也可以检查本主题以获取更多详细信息,并 AlamofireImage GitHub 页面。
Also you can check this topic for more details and AlamofireImage GitHub page.
更多推荐
AlamofireImage缓存?
发布评论