InMemoryRetrostashStore

Thread-safe in-memory RetrostashStore. Backed by a LinkedHashMap guarded by a kotlinx.coroutines.sync.Mutex so it works on every KMP target (no synchronized).

Suitable for short-lived process caches and as the default store for the playground app. For persistence across process restarts on Android, use AndroidRetrostashStore from retrostash-okhttp.

Entry expiry uses kotlin.time.TimeSource.Monotonic, so wall-clock changes don't affect TTLs. No size cap — long-lived caches should pair this with explicit clear() calls or use a size-bounded implementation.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open suspend override fun clear()

Drops every entry. Used by external "clear cache" actions.

Link copied to clipboard
open suspend override fun get(key: String): ByteArray?

Returns the cached payload for key, or null if not present, expired, or unrecoverable. Implementations may evict expired entries as a side effect.

Link copied to clipboard
open suspend override fun invalidate(template: String)

Removes any entries whose key contains |template| as a substring, plus the literal key match if present. template should be the resolved (placeholder-substituted) form (e.g. users/42, not users/{id}). Callers are responsible for the substitution.

Link copied to clipboard
open suspend override fun invalidateTag(tag: String)

Removes every entry whose tag set contains tag. tag must be the resolved tag value (e.g. "article:concept123"). No-op for blank input or when no entries carry that tag.

Link copied to clipboard
open suspend override fun patch(key: String, payload: ByteArray, maxAgeMs: Long?, tags: Set<String>?)

PATCH-style write. Replaces the payload of key but preserves maxAgeMs and tags when their argument is null.

Link copied to clipboard
open suspend override fun put(key: String, payload: ByteArray, maxAgeMs: Long, tags: Set<String>)

Stores payload under key with optional maxAgeMs TTL. 0 or negative means no explicit expiry — the entry lives until invalidated, cleared, or evicted.