Skip to content

Commit 1f02426

Browse files
Documents how Workers interact with Cache Rules (#21614)
1 parent b3e5660 commit 1f02426

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/content/docs/cache/interaction-cloudflare-products/r2.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pcx_content_type: how-to
33
title: Enable cache in an R2 bucket
44
sidebar:
5-
order: 2
5+
order: 3
66
head:
77
- tag: title
88
content: Enable cache in an R2 bucket

src/content/docs/cache/interaction-cloudflare-products/waf-snippets.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pcx_content_type: how-to
33
title: Control cache access with WAF and Snippets
44
sidebar:
5-
order: 3
5+
order: 4
66
head:
77
- tag: title
88
content: Control cache access with WAF and Snippets
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
pcx_content_type: how-to
3+
title: How Workers interact with Cache Rules
4+
sidebar:
5+
order: 2
6+
head:
7+
- tag: title
8+
content: How Workers interact with Cache Rules
9+
10+
---
11+
12+
Your Workers script can override [cache rule](/cache/how-to/cache-rules/) behavior, whether it is applied to a zone using Cloudflare or a zone that is not proxied through Cloudflare.
13+
14+
For example, if there is a cache rule configured to bypass cache for `example.com/foo`, but your Workers script sets `cacheEverything: true`, the script's setting will take precedence, and the request will be cached. The same applies if the request is made to a non-Cloudflare zone — the Worker's `cacheEverything` setting will still override.
15+
16+
## Precedence order
17+
18+
Cache behavior is determined by the following order of precedence:
19+
20+
1. Workers script settings
21+
2. Cache rules
22+
3. Page rules
23+
24+
Cache rules override page rule settings, and Workers scripts override cache rules. Among rules at the same level, the one with the highest specificity takes priority.
25+
26+
## Compatibility flags
27+
28+
This override behavior is controlled by [compatibility flags](/workers/configuration/compatibility-flags/):
29+
30+
- For the Fetch API: `request_cf_overrides_cache_rules`
31+
- For the Cache API: `cache_api_request_cf_overrides_cache_rules`
32+
33+
These flags must be enabled to allow Workers scripts to override cache rules.
34+
35+
If your Worker has a compatibility date of 2025-04-02 or earlier, these flags are not enabled by default. In that case, cache settings defined in the Worker will not override existing cache rules.
36+
37+
### Example (Older compatibility date)
38+
39+
If a cache rule is configured to bypass cache for `example.com/foo`, and a Worker with a compatibility date of `2025-04-02` or earlier tries to set `cacheEverything: true`, the cache rule will take effect — and the response will not be cached.

0 commit comments

Comments
 (0)