A Worker's response is not edge-cached from Cache-Control alone. The client read now uses the Workers Cache API (caches.default) for URL-keyed reads: a hit is answered without a database read, and the stored answer expires on its 15 s max-age, so a flip still reaches every app within 60 s. Header-keyed reads are never cached. Absent in `next dev`, where every read goes through. Tests: bridge 25/25 (new: a URL-keyed read served from the cache, header-keyed reads not cached), console 109/109 with the bundle build, contracts 6/6, SDK 7/7, tsc clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17 lines
647 B
TypeScript
17 lines
647 B
TypeScript
import { deps } from "../../../../../lib/deps.ts";
|
|
import { clientFlags, type EdgeCache } from "../../../../../lib/flags/http.ts";
|
|
|
|
// The Workers edge cache (absent in `next dev`).
|
|
const edgeCache = (): EdgeCache | null => (globalThis as unknown as { caches?: { default?: EdgeCache } }).caches?.default ?? null;
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
// What an app reads with its public flags key (PY2.1). CORS open; cached 15 s.
|
|
export async function GET(req: Request) {
|
|
return clientFlags(deps().flags, req, new Date(), edgeCache());
|
|
}
|
|
|
|
export async function OPTIONS(req: Request) {
|
|
return clientFlags(deps().flags, req, new Date());
|
|
}
|