CoroutineCache

open class CoroutineCache<K, V, S : CoroutineCacheStore<K, V>>(name: String, store: S, cacheScope: CoroutineScope, expireDuration: Duration = 1.minutes)

Base class to create a coroutine and StateFlow based cache.

Parameters

name

The name is just used for logging.

cacheScope

A long living CoroutineScope to spawn coroutines, which remove entries from cache when not used anymore.

expireDuration

Duration to wait until entries from cache are when not used anymore.

Inheritors

Constructors

Link copied to clipboard
constructor(name: String, store: S, cacheScope: CoroutineScope, expireDuration: Duration = 1.minutes)

Properties

Link copied to clipboard
val values: SharedFlow<Map<K, StateFlow<V?>>>

Functions

Link copied to clipboard
Link copied to clipboard
suspend fun clear()
Link copied to clipboard
suspend fun deleteAll()
Link copied to clipboard
fun read(key: K): Flow<V?>
Link copied to clipboard
suspend fun write(key: K, value: V?, persistEnabled: Boolean = true, onPersist: (newValue: V?) -> Unit = {})
suspend fun write(key: K, persistEnabled: Boolean = true, onPersist: (newValue: V?) -> Unit = {}, updater: suspend (oldValue: V?) -> V?)