ExpiringKeyedCache

interface ExpiringKeyedCache<K, V>

A multi-value cache which supports retrieval and invalidation via a key paired with each value. The get and invalidate methods are suspend functions to allow for cross-context synchronization and potentially-expensive value lookup.

Values in the cache may expire and are retrieved as ExpiringValue. When a value is absent/expired in the cache, invoking get will cause a lookup to occur via the function's valueLookup parameter.

Parameters

K

The type of the keys of this cache

V

The type of the values of this cache

Properties

Link copied to clipboard
abstract val size: Int

The number of values currently stored in the cache

Functions

Link copied to clipboard
abstract suspend fun get(key: K, valueLookup: suspend (K) -> ExpiringValue<V>): V

Gets the value associated with this key from the cache. If the cache does not contain the given key, implementations are expected to invoke valueLookup, although they may perform other actions such as throw exceptions, fall back to other caches, etc.

Link copied to clipboard
abstract suspend fun invalidate(key: K)

Invalidates the value (if any) for the given key, removing it from the cache regardless. This method has no effect if the given key is not present in the cache.