jvmMain.dev.kord.cache.map.Lru.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cache-map-jvm Show documentation
Show all versions of cache-map-jvm Show documentation
Adaptable cache with query-like operations
The newest version!
package dev.kord.cache.map
/**
* Creates a least recently used map using a [LinkedHashMap]. The map will start evicting entries once [maxSize] has been reached.
*/
fun MapLikeCollection.Companion.lruLinkedHashMap(maxSize: Int): MapLikeCollection =
from(LRULinkedHashMap(maxSize))
internal class LRULinkedHashMap(
private val maxSize: Int
) : LinkedHashMap(maxSize, 1.0F), MutableMap {
override fun removeEldestEntry(eldest: MutableMap.MutableEntry?): Boolean = size > maxSize
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy