我将AlamofireImage与PromiseKit和Alamofire结合使用。我使用promises来链接x个图像的下载,因为我想同步进行。我似乎不能理解ImageDownloader()是自动缓存还是必须显式地将图像添加到缓存中?到目前为止,我见过的唯一示例都不是使用ImageDownloader,所以我很难找到这个问题的答案。
如果没有-我如何将其添加到缓存中?我试过使用:
self.imageDownloader.imageCache?.addImage(image, withIdentifier: imageUrl)但它所做的就是永远增加我的内存使用量(即一次又一次地将相同的图像添加到缓存中)
发布于 2016-04-25 03:42:39
我认为定义一个AutoPurgingImageCache()然后在缓存过程中使用它需要解决内存使用问题。
let photoCache = AutoPurgingImageCache(
memoryCapacity: 100 * 1024 * 1024,
preferredMemoryUsageAfterPurge: 60 * 1024 * 1024
)您可以更改memoryCapacity,preferredMemoryUsageAfterPurge表示MB。
photoCache.addImage(scaledImage, withIdentifier: urlString)发布于 2020-11-14 03:47:06
我也使用了你在这里做过的相同的方法。但根据API引用,图像应该自动添加到缓存中:
Each downloaded image is cached in the underlying NSURLCache as well as the in-memory image cache that supports image filters.
https://alamofire.github.io/AlamofireImage/Classes/ImageDownloader.html
https://stackoverflow.com/questions/36696288
复制相似问题