Cache

interface Cache<V : Any>

An asynchronous key-value cache.

The Kotlin counterpart of SwiftyNetwork's Cache protocol: all operations are suspend functions and implementations are expected to be safe for concurrent use (e.g. guarded by a kotlinx.coroutines.sync.Mutex). Timestamps are epoch milliseconds.

Type Parameters

V

the cached value type.

Inheritors

Functions

Link copied to clipboard
open fun changes(): Flow<CacheChange>

A hot stream of CacheChanges for this cache. The default is an empty flow, so caches that cannot observe mutations are simply non-reactive; observable caches override this.

Link copied to clipboard
open suspend fun entry(key: CacheKey): CacheEntry<V>?

Atomically returns the value and its timestamp for key, or null if absent.

Link copied to clipboard
abstract suspend fun removeAll()

Removes every entry.

Link copied to clipboard
abstract suspend fun removeValue(key: CacheKey)

Removes any value stored for key.

Link copied to clipboard
abstract suspend fun setValue(value: V, key: CacheKey)

Stores value for key, stamping it with the current time.

Link copied to clipboard
abstract suspend fun timestamp(key: CacheKey): Long?

Returns the epoch-millisecond timestamp recorded for key, or null if absent.

Link copied to clipboard
abstract suspend fun value(key: CacheKey): V?

Returns the value stored for key, or null if absent.