SimpleCache

class SimpleCache<K, V> : Cache<K, V>

Optimized cache implementation for read-heavy workloads.

Uses optimistic reading with a mutex for writes only. This allows concurrent reads without locking.

Note: Read methods are NOT suspend and return snapshots. Write methods ARE suspend and lock the cache.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open suspend override fun clear()

Clear all entries from the cache.

Link copied to clipboard
open override fun contains(key: K): Boolean

Check if a key exists in the cache.

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

Get a value from the cache.

Link copied to clipboard
open suspend override fun getOrPut(key: K, defaultValue: suspend () -> V): V

Get a value or compute and cache it if missing.

Link copied to clipboard
open override fun isEmpty(): Boolean

Check if cache is empty

Link copied to clipboard
open override fun keys(): Set<K>

Get all keys in the cache.

Link copied to clipboard
open suspend override fun put(key: K, value: V)

Store a value in the cache.

Link copied to clipboard
open suspend override fun remove(key: K): V?

Remove a value from the cache.

Link copied to clipboard
open override fun size(): Int

Get the number of cached entries.

Link copied to clipboard
open override fun values(): Collection<V>

Get all values in the cache.