AlamofireImage cache?

你离开我真会死。 提交于 2019-12-11 12:35:18

问题


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)


回答1:


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
)

You can change memoryCapacity, preferredMemoryUsageAfterPurge represent MB. To add any image in your cache, you can use like that:

photoCache.addImage(scaledImage, withIdentifier: urlString)

Also you can check this topic for more details and AlamofireImage GitHub page.



来源:https://stackoverflow.com/questions/36696288/alamofireimage-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!