rename unlimited kv cache

This commit is contained in:
InsanusMokrassar 2022-06-30 00:22:07 +06:00
parent 0d0c16e16d
commit e55f60c30b
5 changed files with 20 additions and 23 deletions

View File

@ -3,4 +3,4 @@ package dev.inmo.micro_utils.repos.cache.cache
/**
* This interface declares that current type of [KVCache] will contains all the data all the time of its life
*/
interface UnlimitedKVCache<K, V> : KVCache<K, V>
interface FullKVCache<K, V> : KVCache<K, V>

View File

@ -5,9 +5,9 @@ import dev.inmo.micro_utils.repos.MapKeyValueRepo
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
open class SimpleUnlimitedKVCache<K, V>(
open class SimpleFullKVCache<K, V>(
private val kvParent: KeyValueRepo<K, V> = MapKeyValueRepo<K, V>()
) : UnlimitedKVCache<K, V>, KeyValueRepo<K, V> by kvParent {
) : FullKVCache<K, V>, KeyValueRepo<K, V> by kvParent {
protected val syncMutex = Mutex()
override suspend fun set(toSet: Map<K, V>) {

View File

@ -6,22 +6,20 @@ import dev.inmo.micro_utils.pagination.PaginationResult
import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging
import dev.inmo.micro_utils.repos.*
import dev.inmo.micro_utils.repos.cache.*
import dev.inmo.micro_utils.repos.cache.cache.KVCache
import dev.inmo.micro_utils.repos.cache.cache.UnlimitedKVCache
import dev.inmo.micro_utils.repos.cache.cache.FullKVCache
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.*
open class FullReadCRUDCacheRepo<ObjectType, IdType>(
protected open val parentRepo: ReadCRUDRepo<ObjectType, IdType>,
protected open val kvCache: UnlimitedKVCache<IdType, ObjectType>,
protected open val kvCache: FullKVCache<IdType, ObjectType>,
protected open val idGetter: (ObjectType) -> IdType
) : ReadCRUDRepo<ObjectType, IdType> {
protected inline fun <T> doOrTakeAndActualize(
action: UnlimitedKVCache<IdType, ObjectType>.() -> Optional<T>,
action: FullKVCache<IdType, ObjectType>.() -> Optional<T>,
actionElse: ReadCRUDRepo<ObjectType, IdType>.() -> T,
actualize: UnlimitedKVCache<IdType, ObjectType>.(T) -> Unit
actualize: FullKVCache<IdType, ObjectType>.(T) -> Unit
): T {
kvCache.action().onPresented {
return it
@ -67,7 +65,7 @@ open class FullReadCRUDCacheRepo<ObjectType, IdType>(
open class FullCRUDCacheRepo<ObjectType, IdType, InputValueType>(
override val parentRepo: CRUDRepo<ObjectType, IdType, InputValueType>,
kvCache: UnlimitedKVCache<IdType, ObjectType>,
kvCache: FullKVCache<IdType, ObjectType>,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
idGetter: (ObjectType) -> IdType
) : FullReadCRUDCacheRepo<ObjectType, IdType>(

View File

@ -4,7 +4,7 @@ import dev.inmo.micro_utils.common.*
import dev.inmo.micro_utils.pagination.Pagination
import dev.inmo.micro_utils.pagination.PaginationResult
import dev.inmo.micro_utils.repos.*
import dev.inmo.micro_utils.repos.cache.cache.UnlimitedKVCache
import dev.inmo.micro_utils.repos.cache.cache.FullKVCache
import dev.inmo.micro_utils.repos.pagination.getAll
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -12,12 +12,12 @@ import kotlinx.coroutines.flow.*
open class FullReadKeyValueCacheRepo<Key,Value>(
protected open val parentRepo: ReadKeyValueRepo<Key, Value>,
protected open val kvCache: UnlimitedKVCache<Key, Value>,
protected open val kvCache: FullKVCache<Key, Value>,
) : ReadKeyValueRepo<Key, Value> {
protected inline fun <T> doOrTakeAndActualize(
action: UnlimitedKVCache<Key, Value>.() -> Optional<T>,
action: FullKVCache<Key, Value>.() -> Optional<T>,
actionElse: ReadKeyValueRepo<Key, Value>.() -> T,
actualize: UnlimitedKVCache<Key, Value>.(T) -> Unit
actualize: FullKVCache<Key, Value>.(T) -> Unit
): T {
kvCache.action().onPresented {
return it
@ -72,7 +72,7 @@ open class FullReadKeyValueCacheRepo<Key,Value>(
open class FullWriteKeyValueCacheRepo<Key,Value>(
protected open val parentRepo: WriteKeyValueRepo<Key, Value>,
protected open val kvCache: UnlimitedKVCache<Key, Value>,
protected open val kvCache: FullKVCache<Key, Value>,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
) : WriteKeyValueRepo<Key, Value> by parentRepo {
protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, it.second) }.launchIn(scope)
@ -81,7 +81,7 @@ open class FullWriteKeyValueCacheRepo<Key,Value>(
open class FullKeyValueCacheRepo<Key,Value>(
parentRepo: KeyValueRepo<Key, Value>,
kvCache: UnlimitedKVCache<Key, Value>,
kvCache: FullKVCache<Key, Value>,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
) : FullWriteKeyValueCacheRepo<Key,Value>(parentRepo, kvCache, scope),
KeyValueRepo<Key,Value>,

View File

@ -4,20 +4,19 @@ import dev.inmo.micro_utils.common.*
import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.pagination.utils.*
import dev.inmo.micro_utils.repos.*
import dev.inmo.micro_utils.repos.cache.cache.UnlimitedKVCache
import dev.inmo.micro_utils.repos.pagination.getAll
import dev.inmo.micro_utils.repos.cache.cache.FullKVCache
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.*
open class FullReadKeyValuesCacheRepo<Key,Value>(
protected open val parentRepo: ReadKeyValuesRepo<Key, Value>,
protected open val kvCache: UnlimitedKVCache<Key, List<Value>>,
protected open val kvCache: FullKVCache<Key, List<Value>>,
) : ReadKeyValuesRepo<Key, Value> {
protected inline fun <T> doOrTakeAndActualize(
action: UnlimitedKVCache<Key, List<Value>>.() -> Optional<T>,
action: FullKVCache<Key, List<Value>>.() -> Optional<T>,
actionElse: ReadKeyValuesRepo<Key, Value>.() -> T,
actualize: UnlimitedKVCache<Key, List<Value>>.(T) -> Unit
actualize: FullKVCache<Key, List<Value>>.(T) -> Unit
): T {
kvCache.action().onPresented {
return it
@ -107,7 +106,7 @@ open class FullReadKeyValuesCacheRepo<Key,Value>(
open class FullWriteKeyValuesCacheRepo<Key,Value>(
protected open val parentRepo: WriteKeyValueRepo<Key, Value>,
protected open val kvCache: UnlimitedKVCache<Key, Value>,
protected open val kvCache: FullKVCache<Key, Value>,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
) : WriteKeyValueRepo<Key, Value> by parentRepo {
protected val onNewJob = parentRepo.onNewValue.onEach { kvCache.set(it.first, it.second) }.launchIn(scope)
@ -116,7 +115,7 @@ open class FullWriteKeyValuesCacheRepo<Key,Value>(
open class FullKeyValuesCacheRepo<Key,Value>(
parentRepo: KeyValueRepo<Key, Value>,
kvCache: UnlimitedKVCache<Key, Value>,
kvCache: FullKVCache<Key, Value>,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
) : FullWriteKeyValueCacheRepo<Key,Value>(parentRepo, kvCache, scope),
KeyValueRepo<Key,Value>,