Alamofire图片:在af_setImageWithURL()之后从AutoPurgingImageCache获取图片 [英] Alamofire Image: Fetch Image from AutoPurgingImageCache after af_setImageWithURL()

查看:234
本文介绍了Alamofire图片:在af_setImageWithURL()之后从AutoPurgingImageCache获取图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用AlamofireImage。我使用 someImageView.af_setImageWithURL(url)很多。

I use AlamofireImage in my project. I use someImageView.af_setImageWithURL(url) a lot.

但是在某些时候我需要手动获取图像来自imageCache,因为我不想将它应用于UIImageView。

However at some point I need to fetch an image manually from the imageCache, because I do not want to apply it to an UIImageView.

这带来了2个问题:


  1. 我可以通过使用创建一个来直接访问图像缓存,让imageCache = AutoPurgingImageCache()。这 .af_setImageWithURL()使用(Singleton)相同的缓存吗?或者这是一个新的?在我的情况下,这是毫无价值的,因为我无法从预先填充的缓存中获利。

  2. 鉴于这是相同的缓存:我如何获取正确的图像?我想过 imageCache.imageForRequest(NSUrlRequest)。如果NSUrlRequest确实使用相同的NSURL,那么我之前用 .af_setImageWithURL()下载的图像是否匹配?

  1. I can access the image cache directly by creating one with let imageCache = AutoPurgingImageCache(). Is this the same cache as .af_setImageWithURL() uses (Singleton)? Or is this a new one? Which is worthless in my case, because I could not profit from the prefilled cache.
  2. Given this is the same cache: How can I fetch the correct image? I thought about imageCache.imageForRequest(NSUrlRequest). Will this match on the images I downloaded before with .af_setImageWithURL() if the NSUrlRequest does use the same NSURL?


推荐答案

问题1



这与 UIImageView的缓存不同使用。如果您需要访问相同的缓存,可以通过 UIImageView.af_sharedImageDownloader.imageCache 来实现。

Question 1

That is not the same cache that UIImageView uses. If you need access the same cache, you can do so by UIImageView.af_sharedImageDownloader.imageCache.

您需要使用完全相同的 NSURLRequest 和相同的 ImageFilter 。如果您使用相同的 NSURLRequest 和相同的 ImageFilter ,则会直接从缓存中提取图像(如果存在)。如果您使用的是另一个 ImageFilter ,则原始图像很可能会从 NSURLCache 中拉出,然后 ImageFilter 将在其上运行,放入 AutoPurgingImageCache 并返回。如果 NSURLRequest 不同,则需要再次下载新图像。

You will need to use the exact same NSURLRequest and the same ImageFilter. If you use the same NSURLRequest and the same ImageFilter, the image will be directly fetched from the cache if it exists. If you are using a different ImageFilter, then the original image will most likely be pulled from the NSURLCache, then the ImageFilter will be run over it, placed into the AutoPurgingImageCache and returned. If the NSURLRequest is different, the new image will need to be downloaded again.

这篇关于Alamofire图片:在af_setImageWithURL()之后从AutoPurgingImageCache获取图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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