opensavvy.cache.contextual¶
Reactive key-context-value store algorithms represented by the ContextualCache interface.
For convenience, adapters are provided:
-
cachecaches calls to anysuspendfunction, -
batchingCacheintercepts subsequent cache requests and batches them into a single larger request.
The following cache layers are available:
-
cachedInMemorystores results in-memory. When values are updated, it continues to show the old values while the new ones are being fetched, -
expireAfterexpires the values stored by the previous layer after some time has passed.
Types¶
ContextualCache¶
interface ContextualCache<Identifier, Context, Failure, Value>
Stores information temporarily to avoid unneeded network requests.
Functions¶
batchingCache¶
fun <Identifier, Context, Failure, Value> batchingCache(
scope: CoroutineScope,
workers: Int = 1,
transform: suspend FlowCollector<Triple<Identifier, Context, ProgressiveOutcome<Failure, Value>>>.(Set<Pair<Identifier, Context>>) -> Unit
): ContextualCache<Identifier, Context, Failure, Value>
Cache implementation which collects cache requests into batches which are queried at the same time.
cache¶
fun <Identifier, Context, Failure, Value> cache(transform: suspend (Identifier, Context) -> Outcome<Failure, Value>): ContextualCache<Identifier, Context, Failure, Value>
Cache implementation which calls a given transform suspending function.