Skip to content

Configuration

Last updated View as MarkdownAgent setup

Workers Caching is configured per Worker, in your Wrangler configuration file. When enabled, caching applies to every fetch() invocation — eyeball requests, service binding fetch() calls, and loopback fetch() calls between entrypoints via ctx.exports — unless you disable it for a specific entrypoint. Custom RPC methods bypass the cache.

This is your Worker's cache — configured through your Worker's code and Wrangler file. Your Worker controls its cache entirely through:

  • The cache.enabled flag in your Wrangler configuration, which turns caching on or off. You can override it per entrypoint and control cross-version behavior.
  • The Cache-Control (and cdn-cache-control, cloudflare-cdn-cache-control) headers your Worker sets on its responses, per RFC 9111.
  • The optional Cache-Tag response header for bulk purging, and ctx.cache.purge() for programmatic invalidation.

That is the entire configuration surface.

Enable caching

Add a cache block to your Wrangler configuration:

{
	"name": "my-worker",
	"main": "src/index.ts",
	// Set this to today's date
	"compatibility_date": "2026-09-16",
	"cache": {
		"enabled": true,
	},
}
name = "my-worker"
main = "src/index.ts"
# Set this to today's date
compatibility_date = "2026-09-16"

[cache]
enabled = true

Setting cache.enabled to true causes Cloudflare to check the cache before invoking your Worker on every HTTP request. This is the default for every entrypoint; you can override it per entrypoint with exports.

The cache block accepts two fields: enabled (required) and cross_version_cache (optional). Any other fields are reserved for future use and may cause validation errors in future versions of Wrangler.

Disable caching

To turn caching off, set cache.enabled to false (or remove the cache block) and redeploy:

{
	"name": "my-worker",
	"main": "src/index.ts",
	// Set this to today's date
	"compatibility_date": "2026-09-16",
	"cache": {
		"enabled": false,
	},
}
name = "my-worker"
main = "src/index.ts"
# Set this to today's date
compatibility_date = "2026-09-16"

[cache]
enabled = false

Disabling caching does not purge previously cached responses — it only stops Cloudflare from consulting or populating the cache on subsequent requests. If you re-enable caching later, any entries that are still within their TTL become usable again. If you need cached responses to stop being served immediately, purge the cache after disabling.

Per-entrypoint caching

cache.enabled sets the default for the whole Worker, but a Worker can expose several entrypoints — the default export and any number of named WorkerEntrypoint classes — and you can turn caching on or off for each one independently. Use the exports map, keyed by entrypoint name, with "default" referring to the default export:

{
	"name": "my-worker",
	"main": "src/index.ts",
	// Set this to today's date
	"compatibility_date": "2026-09-16",
	"cache": {
		"enabled": true,
	},
	"exports": {
		// Opt the default entrypoint out of caching.
		"default": { "type": "worker", "cache": { "enabled": false } },
		// Keep caching on for the Admin entrypoint.
		"Admin": { "type": "worker", "cache": { "enabled": true } },
	},