INTEGRITY Cloudflare Docs

Cache Response Rules

Cache Response Rules allow you to configure cache settings based on request and response attributes. These rules execute prior to caching in the http_response_cache_settings phase, which runs after Cloudflare receives the origin response.

With Cache Response Rules you can:

Cache Response Rules apply to both cached and non-cached (dynamic) responses from the origin. For example, you can strip Set-Cookie headers from responses that are not eligible for caching.

Cache Response Rules can be created in the dashboard, via API, or Terraform.

Availability

The following table describes Cache Response Rules availability per plan.

Free Pro Business Enterprise
Availability Yes Yes Yes Yes
Number of rules 10 25 50 300

Troubleshooting

When troubleshooting Cache Response Rules, use Cloudflare Trace to determine if a rule is triggering for a specific URL.

Relationship with Cache Rules

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.

Key differences:

Example: OCC precedence over Edge TTL

Consider the following scenario:

  1. A Cache Rule sets Edge TTL to override_origin with a value of 7200 seconds (2 hours).
  2. A Cache Response Rule uses set_cache_control to set s-maxage to 3600 seconds (1 hour) with cloudflare_only enabled.
  3. The origin responds with Cache-Control: s-maxage=600.

In this case, the Cache Response Rule takes precedence. Cloudflare caches the asset for 3600 seconds (1 hour) based on the s-maxage directive set by the Cache Response Rule, while visitors still receive the original s-maxage=600 from the origin because cloudflare_only is enabled.

Difference from Workers and Transform Rules

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.

If you need to override Cache-Control directives from the origin (for example, remove private or add s-maxage), use a Cache Response Rule — not a Worker or Transform Rule.

Notes