Skip to content

Available settings

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.

Expression fields

Request fields

FieldTypeDescription
http.cookieStringFull cookie header value
http.hostStringThe HTTP Host header
http.refererStringThe HTTP Referer header
http.user_agentStringThe HTTP User-Agent header
http.request.methodStringThe HTTP request method
http.request.uriStringThe request URI
http.request.uri.pathStringThe URI path
http.request.uri.path.basenameStringThe basename of the URI path
http.request.uri.path.extensionStringThe file extension from the URI path
http.request.uri.queryStringThe query string
http.request.uri.argsMapQuery string arguments as key-value pairs
http.request.uri.args.namesArrayQuery string argument names
http.request.uri.args.valuesArrayQuery string argument values
http.request.full_uriStringThe full request URI including scheme and host
http.request.headersMapRequest headers as key-value pairs
http.request.headers.namesArrayRequest header names
http.request.headers.valuesArrayRequest header values
http.request.cookiesMapParsed cookies as key-value pairs
http.request.accepted_languagesArrayParsed Accept-Language header values

Response fields

FieldTypeDescription
http.response.codeIntegerThe HTTP response status code from the origin
http.response.headersMapResponse headers as key-value pairs
http.response.headers.namesArrayResponse header names
http.response.headers.valuesArrayResponse header values

If you select the Edit expression option, you can enter any of the above response fields.

Functions

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.

Operators

For the full list of operators, refer to Operators.

Available actions

Cache Response Rules support three actions:

ActionDescription
set_cache_settingsStrip headers (ETags, Set-Cookie, Last-Modified) from the origin response before caching.
set_cache_tagsAdd, remove, or set cache tags on the response for targeted purging.
set_cache_controlModify Cache-Control header directives in the origin response.

Action: set_cache_settings

Configures settings related to caching on the origin response. The following parameters are available:

ParameterTypeDescription
strip_etagsBooleanStrip ETag headers from the origin response before caching.
strip_set_cookieBooleanStrip Set-Cookie headers from the origin response before caching.
strip_last_modifiedBooleanStrip Last-Modified headers from the origin response before caching.

API information

API action: set_cache_settings.

API configuration example
"action_parameters": {
"strip_etags": true,
"strip_set_cookie": true,
"strip_last_modified": true
}

Refer to Create a rule via API for complete API examples.


Action: set_cache_tags

Modifies the cache tags associated with the response. Cache tags can be used for targeted cache purging.

ParameterTypeDescription
operationStringRequired. One of: add, remove, set.
valuesArrayA list of cache tag strings. Mutually exclusive with expression.
expressionStringAn expression that evaluates to an array of cache tags. Mutually exclusive with values.

API information

API action: set_cache_tags.

API configuration example (static values)
"action_parameters": {
"operation": "set",
"values": ["api-response", "dynamic-content"]
}
API configuration example (expression)
"action_parameters": {
"operation": "add",
"expression": "split(http.response.headers[\"Surrogate-Keys\"][0], \",\", 1)"
}

Refer to Create a rule via API for complete API examples.


Action: set_cache_control

Modifies Cache-Control header directives in the origin response.

Supported directives

Directives with duration value (seconds):

  • max-age
  • s-maxage
  • stale-if-error
  • stale-while-revalidate

Directives with optional qualifiers (header names):

  • private
  • no-cache

Boolean directives:

  • no-store
  • no-transform
  • must-revalidate
  • proxy-revalidate
  • must-understand
  • public
  • immutable

Directive configuration

The available parameters depend on the directive type.

Directives with duration value

Applies to max-age, s-maxage, stale-if-error, and stale-while-revalidate.

ParameterTypeDescription
operationStringRequired. set or remove.
cloudflare_onlyBooleanWhen enabled, this setting only affects how Cloudflare caches your content. Your visitors still receive the original directive.
valueIntegerDuration in seconds. Required when operation is set.
Directives with optional qualifiers

Applies to private and no-cache.

ParameterTypeDescription
operationStringRequired. set or remove.
cloudflare_onlyBooleanWhen enabled, this setting only affects how Cloudflare caches your content. Your visitors still receive the original directive.
qualifiersArrayOptional list of header names to qualify the directive.
Boolean directives

Applies to no-store, no-transform, must-revalidate, proxy-revalidate, must-understand, public, and immutable.

ParameterTypeDescription
operationStringRequired. set or remove.
cloudflare_onlyBooleanWhen enabled, this setting only affects how Cloudflare caches your content. Your visitors still receive the original directive.

API information

API action: set_cache_control.

API configuration example
"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.