RetrostashEngine

class RetrostashEngine(store: RetrostashStore, keyResolver: CoreKeyResolver = CoreKeyResolver(), timeoutMs: Long = 250)

Transport-agnostic core of Retrostash. Owns the RetrostashStore and resolves cache keys via CoreKeyResolver. Each store call is wrapped in a withTimeoutOrNull of timeoutMs so a stuck or slow store can't block a request — the call falls through to the network instead.

Adapters (RetrostashOkHttpInterceptor, RetrostashKtorRuntime) construct one engine per client and dispatch transport metadata into resolveFromCache, persistQueryResult, invalidateTemplates, invalidateTags, and clearAll.

Constructors

Link copied to clipboard
constructor(store: RetrostashStore, keyResolver: CoreKeyResolver = CoreKeyResolver(), timeoutMs: Long = 250)

Functions

Link copied to clipboard
suspend fun clearAll()

Drops every entry from the underlying store.

Link copied to clipboard
suspend fun invalidateTags(tags: List<String>)

Invalidates every entry whose tag set contains any of tags. tags must be the resolved values (e.g. "article:concept123", not "article:{conceptId}").

Link copied to clipboard
suspend fun invalidateTemplates(templates: List<String>)

Invalidates every entry whose key contains |<template>| for any of templates.

Link copied to clipboard
suspend fun patchQueryResult(metadata: QueryMetadata, payload: ByteArray, maxAgeMs: Long? = null, tagsOverride: Set<String>? = null)

PATCH-style write. Replaces payload under the resolved metadata key. maxAgeMs and tagsOverride use null-means-preserve semantics (see RetrostashStore.patch).

Link copied to clipboard
suspend fun persistQueryResult(metadata: QueryMetadata, payload: ByteArray, maxAgeMs: Long)

Persists payload for the resolved metadata key with TTL maxAgeMs. Tag templates on metadata are resolved against the same bindings / body and persisted alongside the entry. No-op if the key cannot be resolved or the store call times out.

Link copied to clipboard
suspend fun resolveFromCache(metadata: QueryMetadata): ByteArray?

Returns the cached payload for metadata, or null if the key cannot be resolved (missing placeholder bindings), the store has no entry, or the store call exceeded timeoutMs.