Nuke Documentation

Class Image​Cache

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 Int.max.

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.

ImageCache ImageCache ImageCaching ImageCaching ImageCache->ImageCaching

Conforms To

ImageCaching

In-memory image cache.

Initializers

init(cost​Limit:​count​Limit:​)

public init(costLimit: Int = ImageCache.defaultCostLimit(), countLimit: Int = Int.max)  

Initializes Cache.

Parameters

cost​Limit Int

Default value representes a number of bytes and is calculated based on the amount of the phisical memory available on the device.

count​Limit Int

Int.max by default.

Properties

cost​Limit

public var costLimit: Int  

The maximum total cost that the cache can hold.

count​Limit

public var countLimit: Int  

The maximum number of items that the cache can hold.

ttl

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.

total​Cost

public var totalCost: Int  

The total cost of items in the cache.

entry​Cost​Limit

public var entryCostLimit: Double = 0.1

The maximum cost of an entry in proportion to the costLimit. By default, 0.1.

total​Count

public var totalCount: Int  

The total number of items in the cache.

shared

public static let shared  

Shared Cache instance.

Methods

default​Cost​Limit()

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.

remove​All()

public func removeAll()  

Removes all cached images.

trim(to​Cost:​)

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.

trim(to​Count:​)

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.