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

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract operator fun get(key: K): Optional<out V>

Retrieves the cached value corresponding to the provided key

Link copied to clipboard
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

Link copied to clipboard
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

Link copied to clipboard
abstract fun toMap(): Map<K, V>

Converts this cache to an immutable map

Link copied to clipboard
abstract fun toSequence(): Sequence<Pair<K, V>>

Converts this cache to a sequenve of key-value pairs

Properties

Link copied to clipboard
abstract val capacity: Int

Retrieves the maximum amount of items this cache may ever store

Link copied to clipboard
abstract val size: Int

Retrieves the amount of items currently cached by this cache