AutoPurgingImageCache
open class AutoPurgingImageCache : ImageRequestCache
The AutoPurgingImageCache in an in-memory image cache used to store images up to a given memory capacity. When
the memory capacity is reached, the image cache is sorted by last access date, then the oldest image is continuously
purged until the preferred memory usage after purge is met. Each time an image is accessed through the cache, the
internal access date of the image is updated.
-
The current total memory usage in bytes of all images stored within the cache.
Declaration
Swift
open var memoryUsage: UInt64 { get } -
The total memory capacity of the cache in bytes.
Declaration
Swift
public let memoryCapacity: UInt64 -
The preferred memory usage after purge in bytes. During a purge, images will be purged until the memory capacity drops below this limit.
Declaration
Swift
public let preferredMemoryUsageAfterPurge: UInt64
-
Initializes the
AutoPurgingImageCacheinstance with the given memory capacity and preferred memory usage after purge limit.Please note, the memory capacity must always be greater than or equal to the preferred memory usage after purge.
Declaration
Swift
public init(memoryCapacity: UInt64 = 100_000_000, preferredMemoryUsageAfterPurge: UInt64 = 60_000_000)Parameters
memoryCapacityThe total memory capacity of the cache in bytes.
100 MBby default.preferredMemoryUsageAfterPurgeThe preferred memory usage after purge in bytes.
60 MBby default.Return Value
The new
AutoPurgingImageCacheinstance.
-
Adds the image to the cache using an identifier created from the request and optional identifier.
Declaration
Swift
open func add(_ image: Image, for request: URLRequest, withIdentifier identifier: String? = nil)Parameters
imageThe image to add to the cache.
requestThe request used to generate the image’s unique identifier.
identifierThe additional identifier to append to the image’s unique identifier.
-
Adds the image to the cache with the given identifier.
Declaration
Swift
open func add(_ image: Image, withIdentifier identifier: String)Parameters
imageThe image to add to the cache.
identifierThe identifier to use to uniquely identify the image.
-
Removes the image from the cache using an identifier created from the request and optional identifier.
Declaration
Swift
@discardableResult open func removeImage(for request: URLRequest, withIdentifier identifier: String?) -> BoolParameters
requestThe request used to generate the image’s unique identifier.
identifierThe additional identifier to append to the image’s unique identifier.
Return Value
trueif the image was removed,falseotherwise. -
Removes all images from the cache created from the request.
Declaration
Swift
@discardableResult open func removeImages(matching request: URLRequest) -> BoolParameters
requestThe request used to generate the image’s unique identifier.
Return Value
trueif any images were removed,falseotherwise. -
Removes the image from the cache matching the given identifier.
Declaration
Swift
@discardableResult open func removeImage(withIdentifier identifier: String) -> BoolParameters
identifierThe unique identifier for the image.
Return Value
trueif the image was removed,falseotherwise. -
Removes all images stored in the cache.
Declaration
Swift
@discardableResult @objc open func removeAllImages() -> BoolReturn Value
trueif images were removed from the cache,falseotherwise.
-
Returns the image from the cache associated with an identifier created from the request and optional identifier.
Declaration
Swift
open func image(for request: URLRequest, withIdentifier identifier: String? = nil) -> Image?Parameters
requestThe request used to generate the image’s unique identifier.
identifierThe additional identifier to append to the image’s unique identifier.
Return Value
The image if it is stored in the cache,
nilotherwise. -
Returns the image in the cache associated with the given identifier.
Declaration
Swift
open func image(withIdentifier identifier: String) -> Image?Parameters
identifierThe unique identifier for the image.
Return Value
The image if it is stored in the cache,
nilotherwise.
-
Returns the unique image cache key for the specified request and additional identifier.
Declaration
Swift
open func imageCacheKey(for request: URLRequest, withIdentifier identifier: String?) -> StringParameters
requestThe request.
identifierThe additional identifier.
Return Value
The unique image cache key.
View on GitHub
Install in Dash
AutoPurgingImageCache Class Reference