Cache

interface Cache<K, V> : Any

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

Fields

Name Description
abstract capacity: Int

Retrieves the maximum amount of items this cache may ever store

abstract size: Int

Retrieves the amount of items currently cached by this cache

Methods

set

abstract operator fun set(key: K, value: V): Optional<Pair<K, V>>

Stores a new key-value pair in this cache, possibly evicting some previously stored key-value pair

Parameters

Name Description
key: K

is the key used for indexing the pair

value: V

is the value corresponding to key

ReturnValue

Name Description
Optional<Pair<K, V>>

the evicted key-value pair, if any

get

abstract operator fun get(key: K): Optional<V>

Retrieves the cached value corresponding to the provided key

Parameters

Name Description
key: K

is the key used for indexing the pair

ReturnValue

Name Description
Optional<V>

the value corresponding to key, if any

toMap

abstract fun toMap(): Map<K, V>

Converts this cache to an immutable map

ReturnValue

Name Description
Map<K, V>

toSequence

abstract fun toSequence(): Sequence><Pair<K, V>>

Converts this cache to a sequenve of key-value pairs

ReturnValue

Name Description
Sequence><Pair<K, V>>

CompanionObject

Cache

interface Cache<K, V> : Any

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

Methods

lru

fun <K, V> lru(capacity: Int): Cache<K, V>

Creates a new LRU (least recently used) cache

Parameters

Name Description
capacity: Int

ReturnValue

Name Description
Cache<K, V>

simpleLru

fun <K, V> simpleLru(capacity: Int): Cache<K, V>

Creates a new LRU (least recently used) cache, using a simpler (less memory-consuming) implementation

Parameters

Name Description
capacity: Int

ReturnValue

Name Description
Cache<K, V>