Alamofire Image: Fetch Image from AutoPurgingImageCache after af_setImageWithURL()

℡╲_俬逩灬. 提交于 2019-12-03 20:52:57

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.

Question 2

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.

This is answer to the comment: How to download multiple images, save them to cache and get from cache.

Following code will download images from array of URLs and cache them in-memory.

let imageDownloader = ImageDownloader() var URLRequests = [URLRequestConvertible]() URLRequests.append(NSURLRequest(URL: NSURL(string: "https://some/image/some.png")!))
As @cnoon mentioned, to set an image use myUIImageView.af_setImageWithURL(imageUrl)
This will load image from cache if present. If it doesn't exist, then network call will happen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!