RetrostashStore

interface RetrostashStore

Persistent or in-memory backing store for cached query payloads.

Implementations are responsible for thread-safe concurrent access, expiry, and any capacity eviction. Keys are produced by CoreKeyResolver and have the shape scopeName|<resolvedTemplate>|<binding-hash>. Templates passed to invalidate are matched against the middle segment by substring.

Built-in implementations:

  • InMemoryRetrostashStore — LinkedHashMap + Mutex, KMP-safe, ephemeral.

  • AndroidRetrostashStore (in retrostash-okhttp) — Android Context-backed disk store.

Inheritors

Functions

Link copied to clipboard
abstract suspend fun clear()

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

Link copied to clipboard
abstract suspend 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
abstract suspend 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
abstract suspend 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
abstract suspend fun patch(key: String, payload: ByteArray, maxAgeMs: Long? = null, tags: Set<String>? = null)

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

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

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