Skip to content

Cache API

caches.default, caches.open(), put / match / delete. caches.default shares logical storage with that Worker's default HTTP response cache.

ts
export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    const cached = await caches.default.match(request);
    if (cached) return cached;
    const response = new Response("hello", {
      headers: { "Cache-Control": "public, s-maxage=60" },
    });
    ctx.waitUntil(caches.default.put(request, response.clone()));
    return response;
  },
} satisfies ExportedHandler<Env>;

Deployment-side cache.enabled: Workers Cache.

Compatibility

TopicCloudflareopen-compute
caches.default / caches.open / put / match / deleteYes — Cache APIYes
Conditional requests, Vary, RangeYesPinned workerd plus the local cache authority
Cache scopeGlobal / colo CDNSingle-node
Automatic cache TTLMay include heuristic TTLRequires explicit s-maxage or max-age; no heuristic TTL
Global purge / Cache TagsYesNot provided