As the lead for a team's Cloudflare Workers APIs, how do you choose between the Cache API, fetch() cf options and Workers Cache?
answer
- does the Worker need to run?
- origin-backed or computed output
- per location versus tiered
- who purges, and how
- billing on cache hits
basics
~20 sChoose by whether code must run on every request and where content comes from: fetch() cf options for origin proxies, Workers Cache for new Worker-generated output, the Cache API only for fine programmatic control, weighing tiering, purging, per-user keys and billing.
solid answer
~50 sI start with whether code must run on every request. The Cache API and `fetch()` `cf` options both run the Worker each time; Workers Cache sits in front of it and skips it on a hit. For a Worker proxying an origin I standardise on `fetch()` with `cf` options, which reads through Tiered Cache and zone purges. For output the Worker computes, new code uses Workers Cache, as the docs recommend: tiered by default, collapses concurrent misses, purged from code with `ctx.cache.purge()`. Auth or metering goes in an uncached gateway entrypoint in front of it. The Cache API stays for programmatic cases such as caching a `POST` under a hashed key. I also weigh Workers Cache billing every request, hits included, its Free-plan size and purge limits at launch, and one owner for tags and purges.
go deeper
Know that a Worker can cache through the Cache API, through fetch() cf options, or by turning on Workers Cache in front of it, and that only the last skips the Worker on a hit.
Explain how the three differ in reach (per location or tiered), in what controls them, and in how each one is purged.
Match mechanisms to workloads: origin proxies, computed output, code that must run each time, and per-user data that must never share an entry.
Set the team default and its exceptions, weigh the billing change and launch limits of Workers Cache, and name who owns tags and purges.
## Three ways a Worker can cache A Worker on Cloudflare has three separate caching mechanisms, and they do not share entries: - **The Cache API** (`caches.default`, `caches.open()`): the Worker runs on every request and calls `match()` and `put()` itself. - **`fetch()` `cf` options** (`cacheTtl`, `cacheTtlByStatus`, `cacheEverything`, `cacheKey`): the Worker runs on every request, and its subrequests to an origin read through the zone cache. - **Workers Cache**: a cache **in front of** the Worker, turned on with `"cache": { "enabled": true }` in the Wrangler file. On a hit the Worker does not run at all; `Cache-Control` on the Worker's responses is the main configuration. | | Cache API | `fetch()` `cf` options | Workers Cache | |---|---|---|---| | Worker runs on a hit | yes | yes | no | | Reach | one data center | zone cache, Tiered Cache if enabled | tiered by default | | Main control | headers on the stored response | `cf` options and the zone's Cache Rules | `Cache-Control` on the Worker's responses; no zone rules apply | | Purge | local `delete()`, zone purges | zone purges by subrequest URL, tag and more | `ctx.cache.purge()`, `ctx.cache.invalidate()` | | Key | the URL you choose | subrequest URL, or `cacheKey` on Enterprise | path and query, entrypoint, `ctx.props`, version | ## Questions that decide it 1. **Must code run on every request?** Authentication, metering, A/B assignment or per-request logging cannot sit behind Workers Cache unless you split the Worker: an uncached gateway entrypoint that runs every time, calling a cached entrypoint through `ctx.exports`. With the Cache API or `fetch()`, the Worker always runs. 2. **Where does the content come from?** For a Worker proxying an origin, `fetch()` with `cf` options keeps Tiered Cache, zone purges and the team's Cache Rules in one picture. For output the Worker computes, Workers Cache or the Cache API fits. 3. **How hot and how global is the traffic?** A per-location Cache API fill repeats the work in every data center, and the Cache API does not collapse a burst of concurrent misses for one key. Workers Cache is tiered and collapses such a burst into one Worker run, which matters for expensive builds. 4. **How is content invalidated?** The Cache API needs `Cache-Tag` planning and zone purges for global removal. Workers Cache purges by tag, path prefix or everything from code, and its per-version keys mean a deploy starts cold unless `cache.cross_version_cache` is set. 5. **Is any response per user?** Workers Cache leaves request headers such as `Cookie` out of its key; among Cloudflare's standard bypass conditions, `Set-Cookie` and `Authorization` skip the cache automatically, and callers over a service binding are kept apart by `ctx.props`. A custom auth header is not in the key. ## Costs and limits - **Billing changes with Workers Cache**: every request to the Worker is billed at the standard request rate, hits included, even static-asset and service-binding requests that are normally free; CPU time is billed only when the Worker runs. - **Workers Cache limits**: at launch its responses are held to the Free plan's cacheable size whatever the account's plan, and `ctx.cache.purge()` always uses the Free tier's purge rate limits. - **Cache API limits**: 50 calls per request on Workers Free and 1,000 on Workers Paid, shared with subrequests, and 512 MB per object. ## A policy a lead can set - **New Worker-generated content defaults to Workers Cache**, as the docs now recommend, with a gateway entrypoint wherever code must run first. - **Origin proxies use `fetch()` `cf` options**, with lifetimes written in code reviewed beside the zone's Cache Rules. - **The Cache API is the exception**, kept for cases that need programmatic control: caching a `POST` under a hashed key, overwriting what is already cached, or storing a fragment while the Worker still answers each request. - **One owner for tags and purges**: a shared tag vocabulary, and a named person or pipeline allowed to run zone-wide purges. - **A per-user rule**: no shared cache entry for a response that differs by user unless the varying input is in the key, through `ctx.props` or the URL. Teams that skip the decision end up with all three in one codebase, each with its own invalidation path, which makes a stale page hard to trace.
- How do you keep an API-key check running on every request when the Worker's responses sit behind Workers Cache?Split the Worker into entrypoints. The default entrypoint has caching disabled, checks the key on every request, and then calls a cached entrypoint through `ctx.exports`. Only the inner entrypoint's responses are cached. If the callers differ in what they may see, pass that identity in `ctx.props`, which is part of the cache key; a custom header is not.
- Why might a team keep the Cache API even after Workers Cache is available?The Cache API gives explicit control inside a Worker that runs anyway: storing a computed result under a key the Worker chooses, caching a `POST` by hashing its body into a `GET` URL, or overwriting an entry already in `caches.default`. Workers Cache decides from the headers a `fetch` handler returns and never caches custom RPC methods, so those cases still need code.
- The Cache API and Workers Cache share entries, so purging one clears the other
- A Workers Cache hit costs nothing because the Worker never runs
- Zone Cache Rules can tune Workers Cache the same way they tune fetch()
- fetch() cf options skip running the Worker when the response is cached
- A custom auth header keeps users apart in Workers Cache automatically
Assumes the platform as of 2026-10-10, when Workers Cache was newly available with Free-plan size and purge limits for every account and the docs recommended it over the Cache API for new Workers.