public final class ImageCache: ImageCaching
An LRU memory cache.
The elements stored in cache are automatically discarded if either cost or
count limit is reached. The default cost limit represents a number of bytes
and is calculated based on the amount of physical memory available on the
device. The default count limit is set to
ImageCache automatically removes all stored elements when it receives a
memory warning. It also automatically removes most stored elements
when the app enters the background.
In-memory image cache.
public init(costLimit: Int = ImageCache.defaultCostLimit(), countLimit: Int = Int.max)
Default value representes a number of bytes and is calculated based on the amount of the phisical memory available on the device.
public var costLimit: Int
The maximum total cost that the cache can hold.
public var countLimit: Int
The maximum number of items that the cache can hold.
public var ttl: TimeInterval
Default TTL (time to live) for each entry. Can be used to make sure that
the entries get validated at some point.
0 (never expire) by default.
public var totalCost: Int
The total cost of items in the cache.
public var entryCostLimit: Double = 0.1
The maximum cost of an entry in proportion to the
public var totalCount: Int
The total number of items in the cache.
public static func defaultCostLimit() -> Int
Returns a recommended cost limit which is computed based on the amount of the phisical memory available on the device.
public func removeAll()
Removes all cached images.
public func trim(toCost limit: Int)
Removes least recently used items from the cache until the total cost of the remaining items is less than the given cost limit.
public func trim(toCount limit: Int)
Removes least recently used items from the cache until the total count of the remaining items is less than the given count limit.