diff --git a/CHANGELOG.md b/CHANGELOG.md index 145c688168d..062c40c4bdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ * `Fragment`: `1.6.0` -> `1.6.1` * `Repos`: * Fixes In `KeyValueRepo.clear()` of almost all inheritors of `KeyValueRepo` + * `Cache`: + * All full caches got `skipStartInvalidate` property. By default, this property is `false` and fully caching repos + will be automatically invalidated on start of their work ## 0.19.7 diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullCRUDCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullCRUDCacheRepo.kt index f5b55e92148..d1868173dbc 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullCRUDCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullCRUDCacheRepo.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.repos.cache.full import dev.inmo.micro_utils.common.* +import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions import dev.inmo.micro_utils.pagination.Pagination import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.repos.* @@ -84,6 +85,7 @@ open class FullCRUDCacheRepo( override val parentRepo: CRUDRepo, kvCache: FullKVCache, scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + skipStartInvalidate: Boolean = false, idGetter: (ObjectType) -> IdType ) : FullReadCRUDCacheRepo( parentRepo, @@ -97,6 +99,12 @@ open class FullCRUDCacheRepo( idGetter ), CRUDRepo { + init { + if (!skipStartInvalidate) { + scope.launchSafelyWithoutExceptions { invalidate() } + } + } + override suspend fun invalidate() { actualizeAll() } @@ -105,12 +113,14 @@ open class FullCRUDCacheRepo( fun CRUDRepo.fullyCached( kvCache: FullKVCache = FullKVCache(), scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + skipStartInvalidate: Boolean = false, idGetter: (ObjectType) -> IdType -) = FullCRUDCacheRepo(this, kvCache, scope, idGetter) +) = FullCRUDCacheRepo(this, kvCache, scope, skipStartInvalidate, idGetter) @Deprecated("Renamed", ReplaceWith("this.fullyCached(kvCache, scope, idGetter)", "dev.inmo.micro_utils.repos.cache.full.fullyCached")) fun CRUDRepo.cached( kvCache: FullKVCache, scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + skipStartInvalidate: Boolean = false, idGetter: (ObjectType) -> IdType -) = fullyCached(kvCache, scope, idGetter) +) = fullyCached(kvCache, scope, skipStartInvalidate, idGetter) diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValueCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValueCacheRepo.kt index 943a822db19..e75d9ef95be 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValueCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValueCacheRepo.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.repos.cache.full import dev.inmo.micro_utils.common.* +import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions import dev.inmo.micro_utils.pagination.Pagination import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.repos.* @@ -106,10 +107,20 @@ fun WriteKeyValueRepo.caching( open class FullKeyValueCacheRepo( protected open val parentRepo: KeyValueRepo, kvCache: FullKVCache, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default) + scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + skipStartInvalidate: Boolean = false ) : FullWriteKeyValueCacheRepo(parentRepo, kvCache, scope), KeyValueRepo, - ReadKeyValueRepo by FullReadKeyValueCacheRepo(parentRepo, kvCache) { + ReadKeyValueRepo by FullReadKeyValueCacheRepo( + parentRepo, + kvCache +) { + init { + if (!skipStartInvalidate) { + scope.launchSafelyWithoutExceptions { invalidate() } + } + } + override suspend fun unsetWithValues(toUnset: List) = parentRepo.unsetWithValues(toUnset) override suspend fun invalidate() { diff --git a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt index 0946cb5c8fe..8d7ea99e5d1 100644 --- a/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt +++ b/repos/cache/src/commonMain/kotlin/dev/inmo/micro_utils/repos/cache/full/FullKeyValuesCacheRepo.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.repos.cache.full import dev.inmo.micro_utils.common.* +import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.utils.* import dev.inmo.micro_utils.repos.* @@ -142,10 +143,17 @@ fun WriteKeyValuesRepo.caching( open class FullKeyValuesCacheRepo( protected open val parentRepo: KeyValuesRepo, kvCache: FullKVCache>, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default) + scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + skipStartInvalidate: Boolean = false ) : FullWriteKeyValuesCacheRepo(parentRepo, kvCache, scope), KeyValuesRepo, ReadKeyValuesRepo by FullReadKeyValuesCacheRepo(parentRepo, kvCache) { + init { + if (!skipStartInvalidate) { + scope.launchSafelyWithoutExceptions { invalidate() } + } + } + override suspend fun clearWithValue(v: Value) { doAllWithCurrentPaging { keys(v, it).also {