actualize all make it possible to disable clear on actualization

This commit is contained in:
InsanusMokrassar 2023-02-02 20:07:31 +06:00
parent 168d6acf7c
commit 269c2876f3
1 changed files with 13 additions and 7 deletions

View File

@ -11,35 +11,41 @@ import dev.inmo.micro_utils.repos.pagination.getAll
import dev.inmo.micro_utils.repos.set
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
clear: Boolean = true,
getAll: () -> Map<K, V>
) {
set(
getAll().also {
clear()
if (clear) {
clear()
}
}
)
}
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
repo: ReadKeyValueRepo<K, V>
repo: ReadKeyValueRepo<K, V>,
clear: Boolean = true,
) {
actualizeAll {
actualizeAll(clear) {
repo.getAll { keys(it) }.toMap()
}
}
suspend inline fun <K, V> KVCache<K, List<V>>.actualizeAll(
repo: ReadKeyValuesRepo<K, V>
repo: ReadKeyValuesRepo<K, V>,
clear: Boolean = true,
) {
actualizeAll {
actualizeAll(clear) {
repo.getAll { keys(it) }.toMap()
}
}
suspend inline fun <K, V> KVCache<K, V>.actualizeAll(
repo: ReadCRUDRepo<V, K>
repo: ReadCRUDRepo<V, K>,
clear: Boolean = true,
) {
actualizeAll {
actualizeAll(clear) {
repo.getAllByWithNextPaging {
getIdsByPagination(it)
}.mapNotNull { it to (repo.getById(it) ?: return@mapNotNull null) }.toMap()