CacheApiStore

@atiproto/edge-resolver-cache

Implements SimpleStore using the Cloudflare Cache API. Values are serialized to JSON and stored as synthetic HTTP responses with Cache-Control headers for TTL management. The Cache API is regional and survives Worker isolate restarts.

Constructor

typescript
new CacheApiStore<V>(options: CacheApiStoreOptions)
OptionTypeDefaultDescription
ttlSecondsnumberrequiredTime-to-live in seconds for cached values, set via the Cache-Control: max-age header.
cacheNamestring"atproto-resolver"Name of the Cache API cache to open. Namespaces the entries from other caches in the same Worker.
prefixstring""Optional string prepended to all cache keys. Useful when multiple CacheApiStore instances share the same cacheName.

Example

typescript
import { CacheApiStore } from "@atiproto/edge-resolver-cache";
// Cache API only — no memory tier
const store = new CacheApiStore({
ttlSeconds: 3600,
cacheName: "my-cache",
prefix: "did:",
});
await store.set("did:plc:abc123", didDocument);
const doc = await store.get("did:plc:abc123");

Usage with TieredStore

For the typical two-tier setup, pair with a memory store as L1:

typescript
import { CacheApiStore, TieredStore } from "@atiproto/edge-resolver-cache";
import { SimpleStoreMemory } from "@atproto-labs/simple-store-memory";
const tiered = new TieredStore(
new SimpleStoreMemory({ max: 500, ttl: 300_000 }), // L1: memory, 5 minutes
new CacheApiStore({ prefix: "did:", ttlSeconds: 7200 }), // L2: Cache API, 2 hours
);