Skip to content

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:

  • Modify Cache-Control directives sent by your origin.
  • Modify cache tags on responses for targeted cache purging.
  • Strip headers (ETag, Set-Cookie, Last-Modified) from origin responses before caching.

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:

  • Cache eligibility: Cache Rules remain the only mechanism to decide whether content is eligible for caching. However, Cache Response Rules can make a cacheable asset non-cacheable by setting the no-store directive using the set_cache_control action.
  • Origin Cache Control (OCC): If any rule in the http_response_cache_settings phase matches, Cloudflare defaults to Origin Cache Control behavior (origin_cache_control = true).
  • CDN-Cache-Control precedence: Cache-Control directives set by Cache Response Rules take precedence over origin-set Cloudflare-CDN-Cache-Control and CDN-Cache-Control headers. For more information, refer to CDN-Cache-Control header precedence.
  • Stacking: Cache Response Rules stack the same way as Cache Rules. When multiple rules specify the same setting, the last matching rule wins.

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.

Notes

  • If you strip last modified then Smart Edge Revalidation will be turned off.
  • Cache Response Rules ignore HTTP Response 1xx as it is treated as informational responses.