AutoPurgingImageCache

public 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

    public var memoryUsage: UInt64
  • 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
  • Initialies the AutoPurgingImageCache instance 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)
  • Adds the image to the cache using an identifier created from the request and optional identifier.

    Declaration

    Swift

    public func add(_ image: Image, for request: URLRequest, withIdentifier identifier: String? = nil)
  • Adds the image to the cache with the given identifier.

    Declaration

    Swift

    public func add(_ image: Image, withIdentifier identifier: String)
  • Returns the image from the cache associated with an identifier created from the request and optional identifier.

    Declaration

    Swift

    public func image(for request: URLRequest, withIdentifier identifier: String? = nil) -> Image?
  • Returns the image in the cache associated with the given identifier.

    Declaration

    Swift

    public func image(withIdentifier identifier: String) -> Image?