edge-resolver-cache

Tiered DID and handle resolver caching for Cloudflare Workers. Combines an in-memory LRU cache (L1) with the free Cloudflare Cache API (L2) for cache durability across Worker isolate restarts.

Installation

bash
npm install @atiproto/edge-resolver-cache

No KV bindings or additional Cloudflare configuration required. The Cache API is available on all Workers plans at no extra cost.

Quick Setup

Use the createDidCache() and createHandleCache() factory functions with EdgeOAuthClient to replace the default in-memory-only caches:

typescript
import { createDidCache, createHandleCache } from "@atiproto/edge-resolver-cache";
import { EdgeOAuthClient } from "@atiproto/edge-oauth-client";
const client = new EdgeOAuthClient({
// ...
didCache: createDidCache(),
handleCache: createHandleCache(),
});

Cache Tiers

TierBackendLatencyLifetime
L1In-memory LRU~0msWorker isolate lifetime
L2Cloudflare Cache API<1msRegional, survives isolate restarts

Default TTLs

CacheL1 (memory)L2 (Cache API)
DID documents1 hour, ~50MB max24 hours
Handle resolution10 minutes, 1000 entries1 hour

Classes

  • CacheApiStore — Cloudflare Cache API-backed store for a single cache tier
  • TieredStore — Composes two SimpleStore instances into a read-through L1/L2 cache
  • createDidCache — Factory for a pre-configured DID document TieredStore
  • createHandleCache — Factory for a pre-configured handle resolution TieredStore