DelegateBasedKeyValueRepo

Delegate-based implementation of KeyValueRepo that composes separate read and write delegates.

Parameters

readDelegate

Delegate providing all ReadKeyValueRepo operations

writeDelegate

Delegate providing all WriteKeyValueRepo operations

Type Parameters

Key

The type of keys in the repository

Value

The type of values in the repository

Constructors

Link copied to clipboard
constructor(readDelegate: ReadKeyValueRepo<Key, Value>, writeDelegate: WriteKeyValueRepo<Key, Value>)

Properties

Link copied to clipboard
open override val onNewValue: Flow<Pair<Key, Value>>

This flow must emit data each time when data by Key has been changed with set method or in any other way excluding cases of data removing

Link copied to clipboard
open override val onValueRemoved: Flow<Key>

This flow must emit data each time when data by Key has been removed with unset/unsetWithValues methods or in any other way

Functions

Link copied to clipboard
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAll(locker: SmartRWLocker? = null, clearMode: ActualizeAllClearMode = ActualizeAllClearMode.BeforeSet, getAll: () -> Map<K, V>)
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAll(parentRepo: ReadCRUDRepo<V, K>, locker: SmartRWLocker? = null, clearMode: ActualizeAllClearMode = ActualizeAllClearMode.BeforeSet)
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAll(parentRepo: ReadKeyValueRepo<K, V>, locker: SmartRWLocker? = null, clearMode: ActualizeAllClearMode = ActualizeAllClearMode.BeforeSet)
inline suspend fun <K, V> KeyValueRepo<K, List<V>>.actualizeAll(parentRepo: ReadKeyValuesRepo<K, V>, locker: SmartRWLocker? = null, clearMode: ActualizeAllClearMode = ActualizeAllClearMode.BeforeSet)
Link copied to clipboard
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAllWithClearBeforeLoad(getAll: () -> Map<K, V>)
@JvmName(name = "actualizeAllWithClearBeforeLoadWithLocker")
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAllWithClearBeforeLoad(locker: SmartRWLocker, getAll: () -> Map<K, V>)
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAllWithClearBeforeLoad(locker: SmartRWLocker? = null, getAll: () -> Map<K, V>)
Link copied to clipboard
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAllWithClearBeforeSet(getAll: () -> Map<K, V>)
@JvmName(name = "actualizeAllWithClearBeforeSetWithLocker")
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAllWithClearBeforeSet(locker: SmartRWLocker, getAll: () -> Map<K, V>)
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAllWithClearBeforeSet(locker: SmartRWLocker? = null, getAll: () -> Map<K, V>)
Link copied to clipboard
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAllWithoutClear(getAll: () -> Map<K, V>)
@JvmName(name = "actualizeAllWithoutClearWithLocker")
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAllWithoutClear(locker: SmartRWLocker, getAll: () -> Map<K, V>)
inline suspend fun <K, V> KeyValueRepo<K, V>.actualizeAllWithoutClear(locker: SmartRWLocker? = null, getAll: () -> Map<K, V>)
Link copied to clipboard

Applies the given diff to this KeyValueRepo: removes entries in MapDiff.removed, updates entries in MapDiff.changed, and adds entries in MapDiff.added.

Computes the diff between this KeyValueRepo and other, then applies the diff to this repo.

Link copied to clipboard
@JvmName(name = "asListKeyValuesRepo")
fun <K, V> KeyValueRepo<K, List<V>>.asKeyValuesRepo(): KeyValuesFromKeyValueRepo<K, V, List<V>>

Wraps this KeyValueRepo (mapping keys to Lists) as a KeyValuesFromKeyValueRepo. Uses identity conversion for the list iterable.

@JvmName(name = "asSetKeyValuesRepo")
fun <K, V> KeyValueRepo<K, Set<V>>.asKeyValuesRepo(): KeyValuesFromKeyValueRepo<K, V, Set<V>>

Wraps this KeyValueRepo (mapping keys to Sets) as a KeyValuesFromKeyValueRepo. Converts lists to sets when persisting changes, ensuring value uniqueness per key.

fun <K, V, VI : Iterable<V>> KeyValueRepo<K, VI>.asKeyValuesRepo(listToValuesIterable: suspend (List<V>) -> VI): KeyValuesFromKeyValueRepo<K, V, VI>

Wraps this KeyValueRepo (mapping keys to iterables) as a KeyValuesFromKeyValueRepo, exposing a full one-to-many read-write interface.

Link copied to clipboard

Wraps this ReadKeyValueRepo as a ReadCRUDFromKeyValueRepo, exposing CRUD read operations.

Link copied to clipboard

Wraps this ReadKeyValueRepo (mapping keys to iterables) as a ReadKeyValuesFromKeyValueRepo, exposing a one-to-many read interface.

Link copied to clipboard
fun <Key, Value> KeyValueRepo<Key, Value>.cached(kvCache: KVCache<Key, Value>, scope: CoroutineScope = CoroutineScope(Dispatchers.Default), locker: SmartRWLocker = SmartRWLocker()): KeyValueCacheRepo<Key, Value>
Link copied to clipboard
fun <Key, Value> WriteKeyValueRepo<Key, Value>.caching(kvCache: KeyValueRepo<Key, Value>, scope: CoroutineScope = CoroutineScope(Dispatchers.Default)): FullWriteKeyValueCacheRepo<Key, Value>
Link copied to clipboard
open suspend fun clear()

By default, will remove all the data of current repo using doAllWithCurrentPaging, keys and unset

Link copied to clipboard
open suspend override fun contains(key: Key): Boolean
Link copied to clipboard
open suspend override fun count(): Long
Link copied to clipboard

Computes the difference between all entries in this ReadKeyValueRepo and the given other map.

Link copied to clipboard
fun <Key, Value> WriteKeyValueRepo<Key, Value>.directlyCached(kvCache: KeyValueRepo<Key, Value>, scope: CoroutineScope = CoroutineScope(Dispatchers.Default)): DirectFullWriteKeyValueCacheRepo<Key, Value>
Link copied to clipboard
fun <Key, Value> KeyValueRepo<Key, Value>.directlyFullyCached(kvCache: KeyValueRepo<Key, Value> = MapKeyValueRepo(), scope: CoroutineScope = CoroutineScope(Dispatchers.Default), skipStartInvalidate: Boolean = false, locker: SmartRWLocker = SmartRWLocker()): DirectFullKeyValueCacheRepo<Key, Value>
Link copied to clipboard
fun <Key, Value> KeyValueRepo<Key, Value>.fullyCached(kvCache: KeyValueRepo<Key, Value> = MapKeyValueRepo(), scope: CoroutineScope = CoroutineScope(Dispatchers.Default), skipStartInvalidate: Boolean = false, locker: SmartRWLocker = SmartRWLocker()): FullKeyValueCacheRepo<Key, Value>
Link copied to clipboard
open suspend override fun get(k: Key): Value?
Link copied to clipboard
open suspend override fun getAll(): Map<Key, Value>

Returns all key-value pairs in the repository as a Map. Default implementation iterates all pages using keys and get.

Link copied to clipboard
open suspend override fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>

This method should use sorted by Keys search and return the PaginationResult. By default, it should use ascending sort for Keys

open suspend override fun keys(v: Value, pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>

This method should use sorted by Keys search and return the PaginationResult. By default, it should use ascending sort for Keys.

Link copied to clipboard

Creates a pagination starting from the first page with size equal to the total count of items in this ReadKeyValueRepo. This effectively creates a single page containing all items.

Link copied to clipboard
open suspend override fun set(toSet: Map<Key, Value>)

Will set as batch toSet data in current repo. Must pass the data which were successfully updated in repo to onNewValue

Link copied to clipboard
inline suspend fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(toSet: List<Pair<Key, Value>>)

List overload of WriteKeyValueRepo.set accepting a list of pairs.

inline suspend fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(vararg toSet: Pair<Key, Value>)

Vararg overload of WriteKeyValueRepo.set accepting pairs.

inline suspend fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(k: Key, v: Value)

Single-entry overload of WriteKeyValueRepo.set.

Link copied to clipboard
open suspend override fun unset(toUnset: List<Key>)

Will unset as batch data with keys from toUnset. Must pass the Keys which were successfully removed in repo to onValueRemoved

Link copied to clipboard
inline suspend fun <Key, Value> WriteKeyValueRepo<Key, Value>.unset(vararg k: Key)

Vararg overload of WriteKeyValueRepo.unset.

Link copied to clipboard
open suspend override fun unsetWithValues(toUnset: List<Value>)

Will unset as batch data with values from toUnset. Must pass the Keys which were successfully removed in repo to onValueRemoved

Link copied to clipboard
inline suspend fun <Key, Value> WriteKeyValueRepo<Key, Value>.unsetWithValues(vararg v: Value)
Link copied to clipboard
open suspend override fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>

This method should use sorted by Keys search and return the PaginationResult. By default, it should use ascending sort for Keys

Link copied to clipboard

Wraps this KeyValueRepo with a MapperRepo to expose a mapped KeyValueRepo.

Wraps this ReadKeyValueRepo with a MapperRepo to expose a mapped ReadKeyValueRepo.

Wraps this WriteKeyValueRepo with a MapperRepo to expose a mapped WriteKeyValueRepo.

inline fun <FromKey, FromValue, ToKey, ToValue> KeyValueRepo<ToKey, ToValue>.withMapper(noinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey }, noinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue }, noinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey }, noinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue }): KeyValueRepo<FromKey, FromValue>

Wraps this KeyValueRepo with inline conversion lambdas to expose a mapped KeyValueRepo.

inline fun <FromKey, FromValue, ToKey, ToValue> ReadKeyValueRepo<ToKey, ToValue>.withMapper(noinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey }, noinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue }, noinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey }, noinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue }): ReadKeyValueRepo<FromKey, FromValue>

Wraps this ReadKeyValueRepo with inline conversion lambdas to expose a mapped ReadKeyValueRepo.

inline fun <FromKey, FromValue, ToKey, ToValue> WriteKeyValueRepo<ToKey, ToValue>.withMapper(noinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey }, noinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue }, noinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey }, noinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue }): WriteKeyValueRepo<FromKey, FromValue>

Wraps this WriteKeyValueRepo with inline conversion lambdas to expose a mapped WriteKeyValueRepo.