How to clear AlamofireImage setImageWithURL cache
You need to remove the image from the in-memory cache as well as the on-disk cache. You can do this as follows:
func clearImageFromCache() {
let URL = NSURL(string: "https://cdn.domain.com/profile/image.jpg")!
let URLRequest = NSURLRequest(URL: URL)
let imageDownloader = UIImageView.af_sharedImageDownloader
// Clear the URLRequest from the in-memory cache
imageDownloader.imageCache?.removeImageForRequest(URLRequest, withAdditionalIdentifier: nil)
// Clear the URLRequest from the on-disk cache
imageDownloader.sessionManager.session.configuration.URLCache?.removeCachedResponseForRequest(URLRequest)
}
Currently, the URLCache
can only be cleared in this manner on the master
branch. I just pushed f35e4748 which allows access to the underlying sessionManager
in the ImageDownloader
. This is not yet available in an actual release yet, but should be here sometime this week.
Swift - How to save memory using AlamofireImage/ImageShack?
You just have copy & pasted the code from AlamofireImage:
let photoCache = AutoPurgingImageCache(
memoryCapacity: 100 * 1024 * 1024,
preferredMemoryUsageAfterPurge: 60 * 1024 * 1024
)
1024 bytes x 1024 bytes x 100 will create a 100 MB in-memory cache. After that limit is reached the cache size will be reduced to 60 MB. If you do not wan't such a big cache then just reduce it. There is no "correct" number here, it depends solely on your use case. I, personally, use 20 MB in memory cache and 100 MB disk cache.
AlamofireImage is not deallacating the memory
Try to deallocate the image
imgProduct.image = nil
How is Alamofireimage saving the image to disk cache?
It is possible to save the response for the image request on disk. You can init the ImageDownloader
with a modified configuration with your desired NSURLCache and set it also as the UIImageView.af_sharedImageDownloader. Here I've posted an example method for that.
Related Topics
.Sink Is Not Returning the Promise Values from a Future Publisher
How to Reverse an Array in Swift
What Does an Exclamation Mark in a Property in Swift Language
Using Reflection to Set Object Properties Without Using Setvalue Forkey
Stateobject as Parameter for Another Object in Init()
How to Execute Different Implementation of a Method of a Generic Struct Based on the Generic Type
Differencebetween Sequencetype and Collectiontype in Swift
Stopping Timer at Defined Amount of Time in Swift
Array Search Function Not Working in Swift
How to Ensure Make Sure I'm Not Accessing Data Until It's Loaded In
Can't Import Packages Using Swift 4 Package Manager
Need Clarification for Swift Type Properties
Uibuttons Are Not Correctly Shaped on All Devices
How to Create an Operator to Implement Error Chaining
Receiving Data from Nsinputstream in Swift
Apple Vision Framework - Text Extraction from Image
Resizing Large Resolution Images Producing 1000X1000 Pixels Size When Size Is Set to 500X500 Pixels