如何使用 AlmofireImage 最轻松地将 NSURLCache 的内存容量设置为零?
How to most easily set the memory capacity of the NSURLCache to zero with AlmofireImage?
我正在使用 imageView.af_setImageWithURL(URL)
,它运行良好。我没有对图像过滤器做任何事情,我看到了这个注释:
If you do not use image filters, it is advised to set the memory capacity of the NSURLCache to zero to avoid storing the same content in-memory twice.
使用 UIImage 扩展实现此目的的cleanest/smallest 方法是什么?
我正在尝试以下操作:
// From https://github.com/Alamofire/AlamofireImage - "If you do not use image filters, it is advised to set the memory capacity of the NSURLCache to zero to avoid storing the same content in-memory twice."
// Note: We're making an educated guess that NSURLCache does not allocate the memory capacity when it's created.. it just uses it as an upper bound. So we'll let ImageDownloader create the session configuration it wants, then we'll just set the memory capacity on its url cache to 0 as suggested.
let configurationWithNoMemoryCapacityOnURLCache = ImageDownloader.defaultURLSessionConfiguration()
configurationWithNoMemoryCapacityOnURLCache.URLCache?.memoryCapacity = 0
UIImageView.af_sharedImageDownloader = ImageDownloader(
configuration: configurationWithNoMemoryCapacityOnURLCache
)
您的回答一定有效。这是另一种不需要您构建自己的方法 ImageDownloader
.
let downloader = UIImageView.af_sharedImageDownloader
let configuration = downloader.sessionManager.session.configuration
configuration.URLCache?.memoryCapacity = 0
这最终会做同样的事情,而无需创建任何新实例。
我正在使用 imageView.af_setImageWithURL(URL)
,它运行良好。我没有对图像过滤器做任何事情,我看到了这个注释:
If you do not use image filters, it is advised to set the memory capacity of the NSURLCache to zero to avoid storing the same content in-memory twice.
使用 UIImage 扩展实现此目的的cleanest/smallest 方法是什么?
我正在尝试以下操作:
// From https://github.com/Alamofire/AlamofireImage - "If you do not use image filters, it is advised to set the memory capacity of the NSURLCache to zero to avoid storing the same content in-memory twice."
// Note: We're making an educated guess that NSURLCache does not allocate the memory capacity when it's created.. it just uses it as an upper bound. So we'll let ImageDownloader create the session configuration it wants, then we'll just set the memory capacity on its url cache to 0 as suggested.
let configurationWithNoMemoryCapacityOnURLCache = ImageDownloader.defaultURLSessionConfiguration()
configurationWithNoMemoryCapacityOnURLCache.URLCache?.memoryCapacity = 0
UIImageView.af_sharedImageDownloader = ImageDownloader(
configuration: configurationWithNoMemoryCapacityOnURLCache
)
您的回答一定有效。这是另一种不需要您构建自己的方法 ImageDownloader
.
let downloader = UIImageView.af_sharedImageDownloader
let configuration = downloader.sessionManager.session.configuration
configuration.URLCache?.memoryCapacity = 0
这最终会做同样的事情,而无需创建任何新实例。