These are the settings that you can configure when creating a Cache Response Rule. Because Cache Response Rules execute after Cloudflare receives the origin response, both request and response fields are available for rule matching.
| Field | Type | Description |
|---|---|---|
http.cookie |
String | Full cookie header value |
http.host |
String | The HTTP Host header |
http.referer |
String | The HTTP Referer header |
http.user_agent |
String | The HTTP User-Agent header |
http.request.method |
String | The HTTP request method |
http.request.uri |
String | The request URI |
http.request.uri.path |
String | The URI path |
http.request.uri.path.basename |
String | The basename of the URI path |
http.request.uri.path.extension |
String | The file extension from the URI path |
http.request.uri.query |
String | The query string |
http.request.uri.args |
Map | Query string arguments as key-value pairs |
http.request.uri.args.names |
Array | Query string argument names |
http.request.uri.args.values |
Array | Query string argument values |
http.request.full_uri |
String | The full request URI including scheme and host |
http.request.headers |
Map | Request headers as key-value pairs |
http.request.headers.names |
Array | Request header names |
http.request.headers.values |
Array | Request header values |
http.request.cookies |
Map | Parsed cookies as key-value pairs |
http.request.accepted_languages |
Array | Parsed Accept-Language header values |
| Field | Type | Description |
|---|---|---|
http.response.code |
Integer | The HTTP response status code from the origin |
http.response.headers |
Map | Response headers as key-value pairs |
http.response.headers.names |
Array | Response header names |
http.response.headers.values |
Array | Response header values |
If you select the Edit expression option, you can enter any of the above response fields.
The following functions are available in this phase:
- all
- any
- concat
- decode_base64
- ends_with
- len
- lookup_json_integer
- lookup_json_string
- lower
- regex_replace
- remove_bytes
- remove_query_args
- split
- starts_with
- substring
- to_string
- upper
- url_decode
- wildcard_replace
For descriptions of each function, refer to Functions.
For the full list of operators, refer to Operators.
Cache Response Rules support three actions:
| Action | Description |
|---|---|
set_cache_settings |
Strip headers (ETags, Set-Cookie, Last-Modified) from the origin response before caching. |
set_cache_tags |
Add, remove, or set cache tags on the response for targeted purging. |
set_cache_control |
Modify Cache-Control header directives in the origin response. |
Configures settings related to caching on the origin response. The following parameters are available:
| Parameter | Type | Description |
|---|---|---|
strip_etags |
Boolean | Strip ETag headers from the origin response before caching. |
strip_set_cookie |
Boolean | Strip Set-Cookie headers from the origin response before caching. |
strip_last_modified |
Boolean | Strip Last-Modified headers from the origin response before caching. |
API information
API action: set_cache_settings.
"action_parameters": {
"strip_etags": true,
"strip_set_cookie": true,
"strip_last_modified": true
}Refer to Create a rule via API for complete API examples.
Modifies the cache tags associated with the response. Cache tags can be used for targeted cache purging.
| Parameter | Type | Description |
|---|---|---|
operation |
String | Required. One of: add, remove, set. |
values |
Array | A list of cache tag strings. Mutually exclusive with expression. |
expression |
String | An expression that evaluates to an array of cache tags. Mutually exclusive with values. |
API information
API action: set_cache_tags.
"action_parameters": {
"operation": "set",
"values": ["api-response", "dynamic-content"]
}"action_parameters": {
"operation": "add",
"expression": "split(http.response.headers[\"Surrogate-Keys\"][0], \",\", 1)"
}Refer to Create a rule via API for complete API examples.
Modifies Cache-Control header directives in the origin response.
Directives with duration value (seconds):
max-ages-maxagestale-if-errorstale-while-revalidate
Directives with optional qualifiers (header names):
privateno-cache
Boolean directives:
no-storeno-transformmust-revalidateproxy-revalidatemust-understandpublicimmutable
The available parameters depend on the directive type.
Applies to max-age, s-maxage, stale-if-error, and stale-while-revalidate.
| Parameter | Type | Description |
|---|---|---|
operation |
String | Required. set or remove. |
cloudflare_only |
Boolean | When enabled, this setting only affects how Cloudflare caches your content. Your visitors still receive the original directive. |
value |
Integer | Duration in seconds. Required when operation is set. |
Applies to private and no-cache.
| Parameter | Type | Description |
|---|---|---|
operation |
String | Required. set or remove. |
cloudflare_only |
Boolean | When enabled, this setting only affects how Cloudflare caches your content. Your visitors still receive the original directive. |
qualifiers |
Array | Optional list of header names to qualify the directive. |
Applies to no-store, no-transform, must-revalidate, proxy-revalidate, must-understand, public, and immutable.
| Parameter | Type | Description |
|---|---|---|
operation |
String | Required. set or remove. |
cloudflare_only |
Boolean | When enabled, this setting only affects how Cloudflare caches your content. Your visitors still receive the original directive. |
API information
API action: set_cache_control.
"action_parameters": {
"max-age": {
"operation": "set",
"value": 3600,
"cloudflare_only": true
},
"stale-if-error": {
"operation": "remove"
}
}Refer to Create a rule via API for complete API examples.