Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

Worker Response Cache: Configuration, Keys, and Cache-Control

How Cloudflare Workers Caching works, how it differs from zone cache and the Cache API, and how to configure keys, headers, and gateway patterns.

This page summarizes Cloudflare documentation on Workers Caching—a server-side cache that can return HTTP responses without running your Worker—and how it relates to Cache Response Rules, zone Cache Rules, and the programmatic Cache API. If your goal is fewer origin round-trips, lower Worker CPU, and predictable cache keys for multi-tenant APIs, the configuration surface is mostly Cache-Control on responses, Wrangler cache settings, and how you route between entrypoints.

Workers Caching vs zone CDN cache vs Cache API

Section titled “Workers Caching vs zone CDN cache vs Cache API”

Workers Caching sits in front of your Worker’s fetch handlers (browser traffic, service bindings, and ctx.exports loopback). On a cache hit, Cloudflare serves the stored response and your handler does not run.

Workers Cache is your Worker’s cache. It is owned by your Worker, operated by your Worker, and private to your Worker.

— Cloudflare, Workers Cache

Zone-level controls—Cache Rules, Cache Response Rules, Page Rules, and cache level presets—do not apply to Workers Caching. Your Worker’s response headers and code are the configuration mechanism. See Limitations for the full mapping.

The Cache API (caches.default, caches.open()) is a separate, data-center-local store. It does not participate in tiered caching, does not collapse concurrent misses, and always runs your Worker on the way in unless you implement caching yourself. For new designs, Cloudflare recommends Workers Caching when you want edge caching without manual put()/match() orchestration. Background: Cache runtime API and How the Cache works.

When a Worker calls fetch() toward an origin or another zone, that subrequest uses the zone CDN cache (with optional cf overrides), which is independent of Workers Caching. Customize cache behavior with Workers describes middleware flow; Cache using fetch covers cf.cacheTtl, cacheEverything, and related options.

Mechanism What it caches Typical configuration
Workers Caching Responses from your Worker entrypoints Wrangler cache.enabled, Cache-Control, ctx.props
Zone cache + Cache Rules Origin (and some Worker subrequests) Dashboard rules, origin headers, fetch() cf
Cache API Arbitrary Request/Response pairs you store cache.put() / cache.match() in Worker code

Enable Workers Caching: Wrangler cache block and per-entrypoint overrides

Section titled “Enable Workers Caching: Wrangler cache block and per-entrypoint overrides”

Workers Caching is turned on in the Wrangler configuration. With caching enabled, Cloudflare checks the cache before invoking the entrypoint on each eligible HTTP request.

Setting cache.enabled to true causes Cloudflare to check the cache before invoking your Worker on every HTTP request.

— Cloudflare, Workers Cache configuration

The cache block supports enabled (required) and optional cross_version_cache. Per-entrypoint overrides use exports (requires Wrangler 4.107.0+): disable caching on a gateway entrypoint that must run every request, and enable it on inner entrypoints you forward via ctx.exports. See Per-entrypoint caching and Examples.

By default, the Worker version is part of the cache key, so a new deployment starts with a cold cache and never serves entries written by an older version. Setting cross_version_cache: true shares entries across versions until TTL expiry or purge—higher hit rate after deploy, but content changes may linger until you purge. Details: Cross-version caching and Invalidating cache across deployments.

Cache keys: path, entrypoint, version, and ctx.props

Section titled “Cache keys: path, entrypoint, version, and ctx.props”

The cache key decides whether two requests share one stored response. Workers Caching keys primarily on:

  • Target entrypoint (default export vs named WorkerEntrypoint classes do not share cache).
  • Path and query string (parameter order and trailing slashes matter; host is not in the key).
  • Worker version (unless cross_version_cache is enabled).
  • Caller ctx.props on service binding / RPC invocations.

Two requests that produce the same cache key share the same cached response. Two requests that produce different cache keys get independent cached entries.

— Cloudflare, Cache keys

GET and HEAD share one entry; other methods are never cached. Headers such as User-Agent, Cookie, and Authorization are not part of the key—requests that differ only in those headers receive the same body unless you use Vary, branch in code, or partition with ctx.props.

Multi-tenant safety: pass tenant or user id in ctx.props

Section titled “Multi-tenant safety: pass tenant or user id in ctx.props”

For per-caller isolation, put authorization context in ctx.props before ctx.exports.Backend.fetch(). Custom headers used only inside the Worker are not automatically keyed.

Because it is part of the cache key, User A and User B requesting the same URL get separate cache entries — there is no way for one to see the other’s response.

— Cloudflare, Multi-tenant safety with ctx.props

The gateway pattern—auth on default, strip Authorization, forward to a cached inner entrypoint—is documented in Examples and Debugging.

Custom cache keys with cf.cacheKey (same-account loopback only)

Section titled “Custom cache keys with cf.cacheKey (same-account loopback only)”

On ctx.exports calls within your account, the caller may set cf.cacheKey to replace the URL-derived key segment (for example, drop tracking query params). Entrypoint and ctx.props still apply. cf.cacheKey is ignored for eyeball requests and cross-account bindings. See Custom cache keys.

Cache-Control on Worker responses: TTL, bypass, and no-cache

Section titled “Cache-Control on Worker responses: TTL, bypass, and no-cache”

With Workers Caching enabled, your Worker acts as the cache origin: directives on the response determine store duration and browser behavior. Full semantics: Cache-Control configuration.

Responses with no Cache-Control (and no Expires) still may be cached using RFC 9111 heuristic TTLs by status (for example, 200 → 7200 seconds). To opt out, return Cache-Control: no-store or private explicitly.

Automatic bypass (Worker runs every time; Cf-Cache-Status: BYPASS) commonly triggers when:

  • The response includes Set-Cookie (unless qualified private/no-cache for cookies per docs).
  • The request includes Authorization (storage only if response allows shared caching per RFC 9111 §3.5).
  • The response has private or no-store.

Cache-Control: no-cache does not bypass storage; it forces revalidation paths where the Worker still runs and CPU is billed. See Automatic bypass conditions.

For loopback calls, the gateway may supply TTL via cf.cacheControl on the request to a cached callee—same-account only. Override Cache-Control from the calling Worker.

Purging: use Cache-Tag on responses and purge by tags, or ctx.cache.purge() / ctx.cache.invalidate() from the entrypoint that owns the cached response (Examples).

Cache Response Rules: change origin responses before zone cache stores them

Section titled “Cache Response Rules: change origin responses before zone cache stores them”

Cache Response Rules run on the origin response in the http_response_cache_settings phase—unlike Cache Rules, which target the incoming request.

Cache Response Rules operate on the origin response, while Cache Rules operate on the incoming request. When settings from both rule types conflict, Cache Response Rules take precedence.

— Cloudflare, Cache Response Rules

They support three actions (Available settings):

Action Purpose
set_cache_settings Strip ETag, Set-Cookie, Last-Modified before caching
set_cache_tags Add, remove, or set cache tags (including from expressions)
set_cache_control Set or remove Cache-Control directives; optional cloudflare_only so edge TTL differs from what browsers see

Workers and Response Header Transform Rules execute after the caching decision has been made and cannot influence whether or how a response is cached. Only Cache Response Rules can modify caching behavior based on origin response headers.

— Cloudflare, Cache Response Rules

Use Cache Response Rules when the origin sends no-cache or blocking headers but you want Cloudflare’s zone cache to store the asset—without Workers or transform rules. Status-based TTL for zone rules is configured separately; see Cache by status code. For CDN-specific headers from the origin, see CDN-Cache-Control.

fetch() cf object: override zone Cache Rules on subrequests

Section titled “fetch() cf object: override zone Cache Rules on subrequests”

For outbound fetch() from a Worker, properties on request.cf can override zone Cache Rules when the right compatibility flags are active—precedence is Worker script, then Cache Rules, then Page Rules (How Workers interact with Cache Rules).

Workers script settings … Cache rules … Page Rules

— Cloudflare, How Workers interact with Cache Rules

Flags (see Compatibility flags):

  • request_cf_overrides_cache_rules — fetch() with cf properties.
  • cache_api_request_cf_overrides_cache_rules — Cache API put() / match() with cf on the request.

Configurable overrides include cacheEverything, cacheTtl, cacheTtlByStatus, cacheTags, and Enterprise cacheKey (Request cf property). Setting cache: 'no-store' or cache: 'no-cache' on a subrequest follows the Fetch standard for revalidation behavior (changelog).

Inspect behavior: Cf-Cache-Status and common mistakes

Section titled “Inspect behavior: Cf-Cache-Status and common mistakes”

Cf-Cache-Status on each response is the first debugging signal (HIT, MISS, EXPIRED, REVALIDATED, UPDATING, STALE, BYPASS). Workers Caching traces are per Worker, not the zone cache dashboard (Debugging, HTTP headers reference).

Common mistakes

  1. Leaving Authorization on forwarded inner requests — triggers bypass; strip after auth at the gateway (Examples).
  2. Authenticating via a custom header not in the cache key — use ctx.props instead (Multi-tenant safety).
  3. Expecting different cache per hostname on the same path — host is excluded; use ctx.props or paths (The cache belongs to the Worker).
  4. Caching RPC methods — only fetch() on entrypoints uses Workers Caching; refactor to a fetch handler (Limitations).
  5. Confusing Workers Caching with Cache API or zone purge — purging a zone URL does not clear Workers Caching entries; use Worker purge APIs or tags on the owning entrypoint.
  1. Confirm Wrangler has [cache] enabled = true (and per-entrypoint exports if you use a gateway) per Configuration, then deploy and hit a cacheable GET twice.
  2. Read Cf-Cache-Status on the second request; expect HIT when Cache-Control allows storage and bypass rules do not apply (Workers Cache).
  3. For zone origin caching (not Workers Caching), verify Cache Rules and, if used, Cache Response Rules in the dashboard against Cache Response Rules and compare origin vs edge Cache-Control when cloudflare_only is set (Available settings).
  4. Open the Workers observability dashboard and filter invocations for cache-hit metadata as described in Debugging.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page looks wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are questioning so it can be corrected or explained.