class CacheMap<K, V>(val backingMap: MutableMap<K, V> = HashMap()) : Map<K, V>

Cache which can be used to cache and compute entities

Parameters

backingMap

the map which is used to cache the entities, defaults to a Hashmap

Type Parameters

K

the type of the keys under which cached entities are saved

V

the type of the cached entities

Constructors

Link copied to clipboard
constructor(backingMap: MutableMap<K, V> = HashMap())

Properties

Link copied to clipboard
private val backingMap: MutableMap<K, V>
Link copied to clipboard

set of entities which are currently computed using a callback

Link copied to clipboard
open override val entries: Set<Map.Entry<K, V>>
Link copied to clipboard
open override val keys: Set<K>
Link copied to clipboard
open override val size: Int
Link copied to clipboard
open override val values: Collection<V>

Functions

Link copied to clipboard
fun computeIfAbsent(key: K, mappingFunction: Function<in K, out V>): V

Gets the entity in cache under the specified key If no cache entry is found, the mappingFunction is used to create a new entity, which is saved to the cache and returned. Throws an exception if the entity under the provided key is currently computed

fun computeIfAbsent(key: K, alternativeIfComputing: V, mappingFunction: Function<in K, out V>): V

Gets the entity in cache under the specified key If no cache entry is found, the mappingFunction is used to create a new entity, which is saved to the cache and returned. If the value is currently computed, returns alternativeIfComputing

Link copied to clipboard
open override fun containsKey(key: K): Boolean
Link copied to clipboard
open override fun containsValue(value: V): Boolean
Link copied to clipboard
open operator override fun get(key: K): V?
Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
fun putAndInitIfAbsent(key: K, value: V, initFunction: Consumer<V>): V