TimeBasedCache

class TimeBasedCache<K : Any, V : Any>

A time-based cache that evicts entries based on their time-to-live (TTL).

Parameters

K

The type of keys maintained by this cache.

V

The type of mapped values.

Types

Link copied to clipboard
data class Item<K : Any, V : Any>(val key: K, val value: V, val expires: Long) : Comparable<TimeBasedCache.Item<K, V>>

An item in the cache that holds a key, a value, and an expiration time.

Properties

Link copied to clipboard
val keys: Set<K>

Returns the keys contained in this cache.

Link copied to clipboard
val size: Int

Returns the number of entries in this cache.

Functions

Link copied to clipboard
fun clear()

Removes all entries from this cache.

Link copied to clipboard
fun delete(key: K)

Removes the entry for the specified key from this cache if it is present.

Link copied to clipboard
fun evict(now: Long = time())

Evicts entries that have expired.

Link copied to clipboard
operator fun get(key: K): V?

Returns the value of the specified key in this cache

Link copied to clipboard
fun set(key: K, value: V, ttl: Duration)

Save the specified key with value in this cache.

Link copied to clipboard
fun swap(key: K, edit: V.() -> V)

Updates the value associated with the specified key in this cache.

Link copied to clipboard
open override fun toString(): String