CacheStore

interface CacheStore

Storage and nearest-neighbour search behind a SemanticCache.

kmemo splits responsibilities on purpose: the store owns where entries live and when they are dropped (capacity, eviction, TTL), while SemanticCache owns whether a candidate is good enough to serve (threshold, guards, verification). That split is what lets a Redis or pgvector adapter delegate expiry to the database without reimplementing any match logic.

Implementations must honour three rules:

  1. search never returns an expired entry. Expiry is the store's business; the cache trusts it.

  2. search returns at most limit results, sorted by descending similarity.

  3. Every method is safe to call concurrently from multiple coroutines.

Inheritors

Functions

Link copied to clipboard
abstract suspend fun clear(scope: String? = null)

Removes every entry in scope, or the whole store when scope is null.

Link copied to clipboard
abstract suspend fun put(entry: CacheEntry)

Writes entry, replacing any existing entry with the same CacheEntry.id.

Link copied to clipboard
abstract suspend fun remove(id: String): Boolean

Removes the entry id. Returns true if an entry was actually removed.

Link copied to clipboard
abstract suspend fun search(scope: String, embedding: FloatArray, limit: Int): List<ScoredEntry>

Returns up to limit entries from scope closest to embedding, best first.

Link copied to clipboard
abstract suspend fun size(scope: String? = null): Int

Number of live entries in scope, or in the whole store when scope is null.

Link copied to clipboard
open suspend fun touch(id: String)

Signals that the entry id was actually served to a caller.