mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-15 05:19:23 +00:00
fix of full caches initial actualization and realize MapKeyValuesRepo methods getAll
This commit is contained in:
@@ -24,7 +24,9 @@ class ReadMapKeyValueRepo<Key, Value>(
|
||||
) : ReadKeyValueRepo<Key, Value> {
|
||||
constructor(map: Map<Key, Value> = emptyMap()) : this(map, SmartRWLocker())
|
||||
|
||||
override suspend fun get(k: Key): Value? = locker.withReadAcquire { map[k] }
|
||||
override suspend fun get(k: Key): Value? = locker.withReadAcquire {
|
||||
map[k]
|
||||
}
|
||||
|
||||
override suspend fun values(
|
||||
pagination: Pagination,
|
||||
|
@@ -4,6 +4,7 @@ import dev.inmo.micro_utils.coroutines.SmartRWLocker
|
||||
import dev.inmo.micro_utils.coroutines.withReadAcquire
|
||||
import dev.inmo.micro_utils.coroutines.withWriteLock
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import dev.inmo.micro_utils.pagination.utils.optionallyReverse
|
||||
import dev.inmo.micro_utils.pagination.utils.paginate
|
||||
import dev.inmo.micro_utils.pagination.utils.reverse
|
||||
import kotlinx.coroutines.flow.*
|
||||
@@ -33,6 +34,20 @@ class MapReadKeyValuesRepo<Key, Value>(
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun getAll(k: Key, reversed: Boolean): List<Value> {
|
||||
return locker.withReadAcquire { map[k] ?.optionallyReverse(reversed) ?: return emptyList() }
|
||||
}
|
||||
|
||||
override suspend fun getAll(reverseLists: Boolean): Map<Key, List<Value>> {
|
||||
return locker.withReadAcquire {
|
||||
if (reverseLists) {
|
||||
map.mapValues { it.value.reversed() }
|
||||
} else {
|
||||
map.toMap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun keys(pagination: Pagination, reversed: Boolean): PaginationResult<Key> {
|
||||
val keys = locker.withReadAcquire {
|
||||
map.keys
|
||||
|
Reference in New Issue
Block a user