import type { CacheStorage } from "@onenomad/przm-cortex-cache-sqlite"; import type { Widget } from "../types.js"; /** * ADR-019 Phase 1+2 — wrap a widget handler with a SQLite cache layer. * * On each request: compute (workspace, cache_key) from ctx + query, * read the cache, then decide based on the entry's age: * * age <= ttlSeconds → fresh, return cached payload as-is * age <= ttl + staleSeconds → stale-but-serveable, return cached * payload AND fire a background refresh * (deduped per key) to refill the cache * age > ttl + staleSeconds → past serveable window, recompute * synchronously like a miss * miss / payload=null → recompute synchronously * * `ttlSeconds: undefined` (the default) preserves the original Phase 1 * behavior: any cached value is fresh forever. Existing call sites that * passed no opts keep working without change. * * Phase 3 (failure-streak hide-after-3 UI) still pending — recordFailure * is invoked on misses, but the wrapper doesn't yet read failureCount. */ export interface WithCacheOptions { /** * Seconds a cached payload is considered fresh. Older than this, the * SWR window kicks in. Omit (or 0) to disable expiry — the cache then * acts like the Phase 1 implementation. */ ttlSeconds?: number; /** * Seconds beyond `ttlSeconds` we still serve the stale value while a * background refresh runs. Defaults to a generous window so steady- * state dashboard loads stay fast even when the underlying engram * call has gone slow. Set to 0 to opt out of SWR (stale = synchronous * recompute). */ staleSeconds?: number; } export declare function withCache(widget: Widget, cache: CacheStorage, opts?: WithCacheOptions): Widget; //# sourceMappingURL=wrap.d.ts.map