opensavvy.cache¶
Reactive key-value store algorithms represented by the Cache 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¶
Cache¶
interface Cache<Identifier, Failure, Value>
Stores information temporarily to avoid unneeded network requests.
ExperimentalCacheApi¶
@RequiresOptIn(message = "This API has not been stabilized yet. We expect to make breaking changes to it in the future. If you have some ideas of how it could be used, please contact us so we can take it into account.")
annotation class ExperimentalCacheApi
InfallibleCache¶
typealias InfallibleCache<Identifier, Value> = Cache<Identifier, Nothing, Value>
Stores information temporarily to avoid unneeded network requests, with no error strategy.
Functions¶
batchingCache¶
fun <Identifier, Failure, Value> batchingCache(
scope: CoroutineScope,
workers: Int = 1,
transform: suspend FlowCollector<Pair<Identifier, ProgressiveOutcome<Failure, Value>>>.(Set<Identifier>) -> Unit
): Cache<Identifier, Failure, Value>
Cache implementation which collects cache requests into batches which are queried at the same time.
cache¶
@JvmName(name = "infallibleCache")
fun <Identifier, Value> cache(transform: suspend (Identifier) -> Value): InfallibleCache<Identifier, Value>
Cache implementation which calls a given transform suspending function.
fun <Identifier, Failure, Value> cache(transform: suspend (Identifier) -> Outcome<Failure, Value>): Cache<Identifier, Failure, Value>
Cache implementation which calls a given transform suspending function.