AlamofireImage缓存?

编程入门 行业动态 更新时间:2024-10-22 10:42:40
本文介绍了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缓存?

本文发布于:2023-11-26 02:58:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632362.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   AlamofireImage

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!