Cache

class Cache<K : Any, V> : Obtainable<K, V>

Represents cache with specific capacity and counter of access for each item.

Author

Alexander Kornilov (akornilov.82@gmail.com).

Constructors

Cache
Link copied to clipboard
fun <K : Any, V> Cache(capacity: Int, source: Obtainable<K, V>)
Constructs cache with specified capacity and single source.
Cache
Link copied to clipboard
fun <K : Any, V> Cache(capacity: Int, source1: Pair<Obtainable<K, V>, Int>, source2: Pair<Obtainable<K, V>, Int>, vararg sources: Pair<Obtainable<K, V>, Int>)
Constructs cache with specified capacity and multiple sources with priority (less value - more priority): source1, source2 and optional sources.

Functions

clear
Link copied to clipboard
fun clear()
Clears the cache.
contains
Link copied to clipboard
operator fun contains(key: K): Boolean
Indicates that key is present in the cache.
get
Link copied to clipboard
open operator override fun get(key: K): V?
Returns cached item by key.
remove
Link copied to clipboard
fun remove(key: K): Boolean
Removes item from the cache by key.

Properties

isEmpty
Link copied to clipboard
val isEmpty: Boolean
Indicates that the cache is empty at moment.
size
Link copied to clipboard
val size: Int
Holds current cache size in items.