Cache

interface Cache<K, V>

Mutable, fixed-capacity cache whose eviction strategy depends on the specific implementation

Parameters

K

is the type of the keys used for indexing items in this cache

V

is the type of the values stored in this cache

Types

Companion
Link copied to clipboard
common
object Companion

Functions

get
Link copied to clipboard
common
abstract operator fun get(key: K): Optional<out V>
Retrieves the cached value corresponding to the provided key
getOrSet
Link copied to clipboard
common
open fun getOrSet(key: K, valueGenerator: () -> V): V
Retrieves the cached value corresponding to the provided key, or stores a cache for the key in case it is missing
set
Link copied to clipboard
common
abstract operator fun set(key: K, value: V): Optional<out Pair<K, V>>
Stores a new key-value pair in this cache, possibly evicting some previously stored key-value pair
toMap
Link copied to clipboard
common
abstract fun toMap(): Map<K, V>
Converts this cache to an immutable map
toSequence
Link copied to clipboard
common
abstract fun toSequence(): Sequence<Pair<K, V>>
Converts this cache to a sequenve of key-value pairs

Properties

capacity
Link copied to clipboard
common
abstract val capacity: Int
Retrieves the maximum amount of items this cache may ever store
size
Link copied to clipboard
common
abstract val size: Int
Retrieves the amount of items currently cached by this cache