diff --git a/utils/src/main/kotlin/jetbrains/exodus/core/cache/CaffeinePersistentCache.kt b/utils/src/main/kotlin/jetbrains/exodus/core/cache/CaffeinePersistentCache.kt index 778064d1f..4bfbe81e6 100644 --- a/utils/src/main/kotlin/jetbrains/exodus/core/cache/CaffeinePersistentCache.kt +++ b/utils/src/main/kotlin/jetbrains/exodus/core/cache/CaffeinePersistentCache.kt @@ -51,7 +51,7 @@ class CaffeinePersistentCache private constructor( fun put(version: Version, value: V) { map.compute(version) { _, prevValue -> val toSubtract = prevValue?.let(weigher) ?: 0 - totalWeightRef.updateAndGet { it + weigher(value) - toSubtract } + totalWeightRef.updateAndGet { (it + weigher(value) - toSubtract).coerceAtLeast(0) } value } }