问题
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