Cache Response Rules


目录

import { InlineBadge, Render } from "~/components";

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.

:::note Cache Response Rules evaluate the request as it is sent to your origin. If an Origin Rule rewrites the Host header, expressions that match on http.host must use the rewritten hostname. The equivalent Cache Rule still sees the original hostname because Cache Rules run before Origin Rules are applied. :::

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.

:::note Cache Response Rules require that you proxy the DNS records of your domain (or subdomain) through Cloudflare. :::

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

<Render file="troubleshoot-rules-with-trace" product="rules" params={{ rulesFeatureName: "Cache Response Rules" }} />

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


版本号 #2
由 壳壳虫 创建于 2026-11-01 00:13:25 UTC
由 壳壳虫 更新于 2026-11-01 00:13:26 UTC