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
| Tier | Backend | Latency | Lifetime |
|---|---|---|---|
| L1 | In-memory LRU | ~0ms | Worker isolate lifetime |
| L2 | Cloudflare Cache API | <1ms | Regional, survives isolate restarts |
Default TTLs
| Cache | L1 (memory) | L2 (Cache API) |
|---|---|---|
| DID documents | 1 hour, ~50MB max | 24 hours |
| Handle resolution | 10 minutes, 1000 entries | 1 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