Kingfisher Documentation

Class Disk​Storage.​Backend

public class Backend<T: DataTransformable>  

Represents a storage back-end for the DiskStorage. The value is serialized to data and stored as file in the file system under a specified location.

You can config a DiskStorage.Backend in its initializer by passing a DiskStorage.Config value. or modifying the config property after it being created. DiskStorage will use file's attributes to keep track of a file for its expiration or size limitation.

Member Of

DiskStorage

Represents a set of conception related to storage which stores a certain type of value in disk. This is a namespace for the disk storage types. A Backend with a certain Config will be used to describe the storage. See these composed types for more information.

Initializers

init(config:​)

public convenience init(config: Config) throws  

Creates a disk storage with the given DiskStorage.Config.

Parameters

config Config

The config used for this disk storage.

Throws

An error if the folder for storage cannot be got or created.

Properties

config

public var config: Config

The config used for this disk storage.

directory​URL

public let directoryURL: URL

Methods

store(value:​for​Key:​expiration:​)

public func store(
            value: T,
            forKey key: String,
            expiration: StorageExpiration? = nil) throws

Stores a value to the storage under the specified key and expiration policy.

Parameters

value T

The value to be stored.

key String

The key to which the value will be stored. If there is already a value under the key, the old value will be overwritten by value.

expiration Storage​Expiration?

The expiration policy used by this store action.

Throws

An error during converting the value to a data format or during writing it to disk.

value(for​Key:​extending​Expiration:​)

public func value(forKey key: String, extendingExpiration: ExpirationExtending = .cacheTime) throws -> T?  

Gets a value from the storage.

Parameters

key String

The cache key of value.

extending​Expiration Expiration​Extending

The expiration policy used by this getting action.

Throws

An error during converting the data to a value or during operation of disk files.

Returns

The value under key if it is valid and found in the storage. Otherwise, nil.

is​Cached(for​Key:​)

public func isCached(forKey key: String) -> Bool  

Whether there is valid cached data under a given key.

Parameters

key String

The cache key of value.

Returns

If there is valid data under the key, true. Otherwise, false.

is​Cached(for​Key:​reference​Date:​)

public func isCached(forKey key: String, referenceDate: Date) -> Bool  

Whether there is valid cached data under a given key and a reference date.

Parameters

key String

The cache key of value.

reference​Date Date

A reference date to check whether the cache is still valid.

Returns

If there is valid data under the key, true. Otherwise, false.

remove(for​Key:​)

public func remove(forKey key: String) throws  

Removes a value from a specified key.

Parameters

key String

The cache key of value.

Throws

An error during removing the value.

remove​All()

public func removeAll() throws  

Removes all values in this storage.

Throws

An error during removing the values.

cache​File​URL(for​Key:​)

public func cacheFileURL(forKey key: String) -> URL  

The URL of the cached file with a given computed key.

Parameters

key String

The final computed key used when caching the image. Please note that usually this is not the cacheKey of an image Source. It is the computed key with processor identifier considered.

remove​Expired​Values()

public func removeExpiredValues() throws -> [URL]  

Removes all expired values from this storage.

Throws

A file manager error during removing the file.

Returns

The URLs for removed files.

total​Size()

public func totalSize() throws -> UInt  

Gets the total file size of the folder in bytes.