mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-11-14 02:50:25 +00:00
fixes in KeyValueRepo.clear
This commit is contained in:
@@ -38,7 +38,7 @@ fun <Key, Value> ReadKeyValueRepo<Key, Value>.cached(
|
||||
) = ReadKeyValueCacheRepo(this, kvCache)
|
||||
|
||||
open class KeyValueCacheRepo<Key,Value>(
|
||||
parentRepo: KeyValueRepo<Key, Value>,
|
||||
override val parentRepo: KeyValueRepo<Key, Value>,
|
||||
kvCache: KVCache<Key, Value>,
|
||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||
) : ReadKeyValueCacheRepo<Key,Value>(parentRepo, kvCache), KeyValueRepo<Key,Value>, WriteKeyValueRepo<Key, Value> by parentRepo, CommonCacheRepo {
|
||||
@@ -46,6 +46,11 @@ open class KeyValueCacheRepo<Key,Value>(
|
||||
protected val onRemoveJob = parentRepo.onValueRemoved.onEach { kvCache.unset(it) }.launchIn(scope)
|
||||
|
||||
override suspend fun invalidate() = kvCache.clear()
|
||||
|
||||
override suspend fun clear() {
|
||||
parentRepo.clear()
|
||||
kvCache.clear()
|
||||
}
|
||||
}
|
||||
|
||||
fun <Key, Value> KeyValueRepo<Key, Value>.cached(
|
||||
|
||||
@@ -21,6 +21,12 @@ open class SimpleFullKVCache<K, V>(
|
||||
kvParent.unset(toUnset)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
syncMutex.withLock {
|
||||
kvParent.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <K, V> FullKVCache(
|
||||
|
||||
@@ -37,6 +37,10 @@ open class SimpleKVCache<K, V>(
|
||||
override suspend fun unset(toUnset: List<K>) {
|
||||
syncMutex.withLock { makeUnset(toUnset) }
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
syncMutex.withLock { makeUnset(cacheQueue) }
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <K, V> KVCache(
|
||||
|
||||
@@ -39,4 +39,9 @@ open class AutoRecacheKeyValueRepo<Id, RegisteredObject>(
|
||||
).also {
|
||||
kvCache.unsetWithValues(toUnset)
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
originalRepo.clear()
|
||||
kvCache.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,11 @@ open class FullKeyValueCacheRepo<Key,Value>(
|
||||
override suspend fun invalidate() {
|
||||
kvCache.actualizeAll(parentRepo)
|
||||
}
|
||||
|
||||
override suspend fun clear() {
|
||||
parentRepo.clear()
|
||||
kvCache.clear()
|
||||
}
|
||||
}
|
||||
|
||||
fun <Key, Value> KeyValueRepo<Key, Value>.fullyCached(
|
||||
|
||||
Reference in New Issue
Block a user