
io.p8e.util.SizedConcurrentHashMap.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of p8e-common Show documentation
Show all versions of p8e-common Show documentation
A collection of services and libraries that iteract and run Provenance Java based contracts.
The newest version!
package io.p8e.util
import java.util.concurrent.ConcurrentHashMap
import java.util.function.Function
// TODO fix this to a guava hash map or something so we can remove least used keys or time based
// expiration? This max size could be the source of our occasional OOMs
class SizedConcurrentHashMap(private val maxSize: Int = MAX_CACHE_SIZE): ConcurrentHashMap() {
companion object {
private const val MAX_CACHE_SIZE = 10000
}
override fun computeIfAbsent(key: K, mappingFunction: Function): V {
if (size > maxSize)
clear()
return super.computeIfAbsent(key, mappingFunction)
}
override fun put(key: K, value: V): V? {
if (size > maxSize)
clear()
return super.put(key, value)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy