Post

Cloudflare just gave every Worker its own cache — not the zone's cache, the Worker's own. One line in wrangler config + the same Cache-Control headers you already know. No dashboard, no rules engine, no second product to configure. 🧵👇 #cloudflare #workers #cache #buildinpublic

Why this matters: Workers used to sit in front of an origin. Now frameworks like Astro, Next.js, Remix & SvelteKit ship Cloudflare adapters where the Worker IS the origin — every request re-ran your code with nothing to cache. Workers Cache flips that.

Config is tiny. Add this to wrangler.jsonc: `{ "cache": { "enabled": true } }` Then just set Cache-Control on your Response like normal HTTP, and purge with `ctx.cache.purge({ tags: [...] })` That's the entire API surface.

`stale-while-revalidate` is what makes it feel instant. When a cache entry expires, Cloudflare serves the stale copy immediately while your Worker refreshes it in the background. No visitor ever waits on a cold render after the very first request.

0 reposts0 likes

Vary header support means one URL can have multiple cached variants — HTML vs JSON, WebP vs JPEG, per-locale pages — without losing caching entirely. It's standard HTTP content negotiation, not a Cloudflare-specific workaround.

The multi-tenant trick: `ctx.props` (e.g. a userId) becomes part of the cache key when one Worker calls another via a service binding. That lets you safely cache authenticated, per-user API responses instead of just bypassing cache for anything with auth.

Biggest unlock IMO: the cache sits in front of every entrypoint, including `ctx.exports` calls between entrypoints in the same Worker. Chain auth → routing → expensive backend as separate entrypoints, and drop caching in exactly where you want it — in code.

It's regionally tiered by default, no config needed. The first request anywhere on Earth populates the upper tier, so a hit in Singapore can serve a request from the US without your Worker ever running. Also composes cleanly with Smart Placement.