Cache

Cache is workflow-scoped, expiring optimization data. Correctness must tolerate a miss, expiry, eviction, or different state location.

JavaScript
const cached = await services.cache.get("customer:42");
if (cached.hit) return cached.value;

const value = await loadCustomer();
await services.cache.set("customer:42", value, { ttl: "15m" });
return value;
MethodResult/behavior
get(key){ hit: true, value, expiresAt } or { hit: false }.
set(key, value, { ttl?, name? })Replaces value; returns { stored: true, expiresAt }.
delete(key, options?)Returns { deleted }.
has(key)Returns { present }.
increment(key, amount?, options?)Atomic safe-integer addition; missing starts at zero.
setIfAbsent(key, value, options?)Atomic one-winner initialization.

TTL defaults to 5m, ranges from 1 ms through 30 days, and may be milliseconds or duration text. The local cache stores at most 10,000 entries, 64 MiB total, 256 KiB per value, and 256 UTF-8 bytes per key. It removes expired entries then evicts least-recently-used entries. Unexpired values survive local restart but are never durable business state.