Cache (remember)

cache.remember(key, ttl, fn) returns the cached value or computes it once and memoizes it. Here two identical calls: the first builds the report, the second is served from cache — same timestamp, the factory ran once. Pluggable store (shared SDK KV, or per-isolate memory).

Tip
createCache JSON-serializes, so you cache typed objects. remember distinguishes absent from a falsy value: false, 0 and the empty string are cached (not recomputed). kvStore shares across requests and processes; memoryStore is per-isolate (short-lived).

Run it to watch remember() compute once, then cache.

src/app/examples/cache/page.tsxTSX
import { createCache, kvStore } from "@bext-stack/framework/kv";

const cache = createCache({ store: kvStore({ appId: "my-site" }) });

// Compute once, serve from cache within the TTL:
const report = await cache.remember("report:monthly", 300, () => buildReport());

// Plain get / put / forget:
await cache.put("flag", true, 60);
await cache.get<boolean>("flag");   // true | null
await cache.forget("flag");

// pull (get + forget), add (set-if-absent):
const token = await cache.pull("one-time");
const won = await cache.add("lock", 1, 10);  // true only if it was not set