Skip to content
open-computeopen-computeopen-compute

Cache API

caches.defaultcaches.open()put / match / deletecaches.default 与该 Worker 的默认 HTTP response cache 共享逻辑存储。

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>;

部署侧 cache.enabledWorkers Cache

主题 Cloudflare open-compute
caches.default / caches.open / put / match / delete 是,见 Cache API
条件请求、Vary、Range 按 pinned workerd 与本机 cache
缓存范围 全球 / colo CDN 单节点
自动缓存 TTL 可含启发式 TTL 需要显式 s-maxagemax-age;无启发式 TTL
全球 purge / Cache Tags 不提供