How Workers interact with Cache Rules
When you use both Cache Rules and Workers on the same request, the Worker's cache settings take priority — but only when the required compatibility flags are enabled.
Your Workers script can override Cache Rules behavior, whether the request is for a domain proxied through Cloudflare or a domain that is not. For example, if a Cache Rule is configured to bypass cache for example.com/foo, but your Workers script sets cacheEverything: true in the cf object of a fetch() request, the Worker's setting takes precedence and the response is cached.
Cache behavior is determined by the following order of precedence:
- Workers script settings
- Cache rules
- Page rules
Workers override Cache Rules, and Cache Rules override Page Rules. When multiple rules at the same level match the same request, the last matching rule wins for any conflicting settings.
The override behavior is controlled by compatibility flags — configuration settings that opt your Worker into specific runtime behaviors. There are two flags because Workers have two ways to interact with the cache:
- For the Fetch API (
fetch()withcfproperties):request_cf_overrides_cache_rules - For the Cache API (
caches.default.put()/caches.default.match()):cache_api_request_cf_overrides_cache_rules
These flags must be enabled to allow Workers scripts to override Cache Rules. If the correct flag is not enabled for the API you are using, your Worker's cache settings are silently ignored and Cache Rules apply instead.
A Worker's compatibility date determines which flags are active by default. When you set a compatibility date, all flags with an enable date on or before that date are automatically turned on.
| Flag | Enabled by default | Prerequisite |
|---|---|---|
request_cf_overrides_cache_rules (Fetch API) | Compatibility dates on or after 2025-04-02 | None |
cache_api_compat_flags | Compatibility dates on or after 2025-04-19 | None |
cache_api_request_cf_overrides_cache_rules (Cache API) | Compatibility dates on or after 2025-05-19 | Requires cache_api_compat_flags |
The Cache API has an extra requirement: cache_api_compat_flags must be enabled for any compatibility flags to take effect on the Cache API. Without it, the Cache API ignores all compatibility flags, even ones you explicitly list in your configuration.
If your Worker uses a compatibility date before the dates listed above, you must manually add the flags to your configuration. Otherwise, cache behavior follows Cache Rules instead of the Worker's settings.
A Cache Rule bypasses cache for example.com/foo. A Worker with a compatibility date before 2025-04-02 sets cacheEverything: true via fetch(). Because the compatibility date is too old for request_cf_overrides_cache_rules to be active by default, the Cache Rule wins and the response is not cached.
Similarly, if you use the Cache API and your compatibility date is before 2025-04-19, cache_api_compat_flags is not active. Even if you manually add cache_api_request_cf_overrides_cache_rules to your configuration, it has no effect because the Cache API does not recognize compatibility flags without cache_api_compat_flags.