InMemoryStore
Default CacheStore: entries in a map, search by scanning them.
Good enough to start with and honest about its ceiling. Search is a linear scan of every entry in the scope, so cost grows with cache size — at the default 10,000 entries and 1,536-dimensional vectors a lookup is well under a millisecond, which is nothing next to the network call it replaces. Past roughly 100,000 entries, or as soon as you want the cache shared between instances or to survive a restart, move to a real vector store.
Eviction is least-recently-used, not least-recently-written, and "used" means served: only a confirmed hit calls touch. An entry that keeps scoring second place never gets credit for it.
Every method takes a mutex, so the store is safe to share across coroutines and threads.
Parameters
hard cap across all scopes; the least recently used entry goes first.
how long an entry stays valid, or null to keep entries until they are evicted. Expired entries are never returned by search and are dropped as they are encountered.
time source; substitute a fixed clock in tests instead of sleeping.
optional cap on estimated resident bytes (embeddings dominate: dimensions * 4 each), evicted least-recently-used just like maxEntries, so a cache in a memory-constrained service cannot grow without bound. null (the default) bounds by count only.
optional sink notified with a CacheEvent.Eviction whenever an entry is evicted (for capacity or memory) or dropped for being expired — the store owns eviction, so the store is what reports it. Called inline while the store's lock is held, so it must be fast and non-blocking (see CacheListener); pass the same listener you give dev.kmemo.SemanticCache to see the whole event stream in one place. null (the default) emits nothing.
Constructors
Functions
Drops every expired entry and returns how many were removed.
Writes entry, replacing any existing entry with the same CacheEntry.id.
Current size and lifetime eviction counters.