AlamofireImage缓存? [英] AlamofireImage cache?

查看:159
本文介绍了AlamofireImage缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 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缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆