-
Notifications
You must be signed in to change notification settings - Fork 10.1k
[Cache] Documents how Workers interact with Cache Rules #21614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/content/docs/cache/interaction-cloudflare-products/workers-cache-rules.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| --- | ||
| pcx_content_type: how-to | ||
| title: How Workers interact with Cache Rules | ||
| sidebar: | ||
| order: 2 | ||
| head: | ||
| - tag: title | ||
| content: How Workers interact with Cache Rules | ||
|
|
||
| --- | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| ## Precedence order | ||
|
|
||
| Cache behavior is determined by the following order of precedence: | ||
|
|
||
| 1. Workers script settings | ||
| 2. Cache rules | ||
| 3. Page rules | ||
|
|
||
| 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. | ||
|
|
||
| ## Compatibility flags | ||
|
|
||
| This override behavior is controlled by [compatibility flags](/workers/configuration/compatibility-flags/): | ||
|
|
||
| - For the Fetch API: `request_cf_overrides_cache_rules` | ||
| - For the Cache API: `cache_api_request_cf_overrides_cache_rules` | ||
|
|
||
| These flags must be enabled to allow Workers scripts to override cache rules. | ||
|
|
||
| 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. | ||
|
|
||
| ### Example (Older compatibility date) | ||
|
|
||
| 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. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.