Available settings
These are the settings that you can configure when creating a cache rule.
Fields
The fields available for Cache Rule matching expressions in the Expression Builder are:
- Cookie -
http.cookie
- Hostname -
http.host
- Referer -
http.referer
- SSL/HTTPS -
ssl
- URI Full -
http.request.full_uri
- URI -
http.request.uri
- URI Path -
http.request.uri.path
- URI Query String -
http.request.uri.query
- User Agent -
http.user_agent
- X-Forwarded-For -
http.x_forwarded_for
- Request Headers -
http.request.headers
- Cookie value of -
http.request.cookies
For a list of all available fields refer to Fields.
Operators
The operators available for Cache Rule expressions are:
- equals
- does not equal
- contains
- does not contain
- matches regex
- does not match regex
- is in
- is not in
- starts with
- ends with
- does not start with
- does not end with
Cache eligibility
In Cache eligibility, you have the option to select Bypass cache if you want matching requests to not be cached, or Eligible for cache if you want Cloudflare to attempt to cache them.
Bypass cache
When creating a cache rule, you have the option to select Bypass cache if you want matching incoming requests to not be cached. Alternatively, you can use Development Mode, if you want to bypass cache for shorter periods.
Eligible for cache settings
When you select Eligible for cache, you can change the configuration settings described below.
Edge TTL
Edge Cache TTL refers to the maximum cache time-to-live (TTL), or how long an asset should be considered fresh or available to serve from Cloudflare’s cache in response to requests. This setting has three primary options:
- Use cache control-header if present, bypass cache if not: If a cache-control header is present on the response, follow its directives. If not, skip caching entirely.
- Use cache-control header if present, use default Cloudflare caching behavior if not: If a cache-control header is present on the response, follow its directives. If not, cache in accordance with our default cache settings.
- Ignore cache-control header and use this TTL: Completely ignore any cache-control header on the response and instead cache the response for a duration specified in the timing dropdown.
Additionally, you can select how long you would like a particular matching status code’s content to be cached in Cloudflare’s global network. In Status Code TTL section you can define the TTL duration for one or more status codes of responses from the origin server. This setting can be applied to a Single code status code, to a Greater than or equal or Less than or equal status code, or to a Range of status codes. Status code TTLs are similar to Ignore cache-control header and use this TTL in that the cache-control header on the response will be ignored in favor of the TTL specified by the cache rule. For more information, refer to Status code TTL. API configuration object name: Refer to Create a cache rule via API for complete API examples.API information
"edge_ttl"
.API values Configuration respect_origin
Use cache-control header if present, use default Cloudflare caching behavior if not. override_origin
Ignore cache-control header and use this TTL. bypass_by_default
Use cache control-header if present, bypass cache if not. API configuration example
Browser TTL
Browser TTL refers to the maximum cache time-to-live (TTL) that an asset should be considered available to serve from the browser’s cache.
Select if you want to Bypass cache, Respect origin, or Override origin. If you wish to override the browser TTL value, define how long resources cached by client browsers will remain valid from the dropdown menu. For more information, refer to Browser Cache TTL. API configuration object name: API values for the API values for the Refer to Create a cache rule via API for complete API examples.API information
"browser_ttl"
."mode"
property: "respect_origin"
, "override_origin"
, "bypass_by_default"
."default"
property (integer): values available depend on your plan. Refer to Browser Cache TTL.API configuration example
Cache Key
Cache keys refer to the criteria that Cloudflare uses to determine how to store resources in our cache. Customizing the cache key allows you to determine how Cloudflare can reuse particular cache entries across requests or share the cache entries for more granularity for end users.
Define the request components used to define a custom cache key, customizing the following options:
- You can switch on or off Cache by device type, Cache deception armor, Ignore query string, and Sort query string.
Enterprise customers have these additional options for custom cache keys:
- In the Query string section, you can select All query string parameters, All query string parameters except and enter an exception, Only these parameters and enter the parameters, or Ignore query string (also available for pay-as-you-go customers).
- In the Headers section, you can include headers names and their values, check the presence of another header, and Include origin header.
- In the Cookie section, you can include cookie names and their values, and check for the presence of another cookie.
- In the Host section, you can select Use original host and Resolved host. In the User section, you can select Device type, Country, and Language.
API information
API configuration object name: "cache_key"
.
API values: "ignore_query_strings_order"
, "cache_deception_armor"
, "cache_by_device_type"
, "custom_key"
("header"
, "cookie"
, "host"
, "query_string"
, "user"
).
API configuration example"action_parameters": { "cache": true, "cache_key": { "ignore_query_strings_order": true, "cache_deception_armor": true, "custom_key": { "query_string": { "include": [ "*" ] }, "header": { "include": [ "header1" ], "check_presence": [ "header_1" ] }, "cookie": { "include": [ "cookieName1" ], "check_presence": [ "cookie_1" ] }, "user": { "device_type": true, "geo": true, "lang": true }, "host": { "resolved": false } } }
}
Refer to Create a cache rule via API for complete API examples.
Cache Reserve Eligibility
Cache Reserve eligibility allows you to specify which website resources should be eligible for our persistent cache called Cache Reserve. If the request matches and also meets eligibility criteria, Cloudflare will write the resource to cache reserve. This requires an add-on cache reserve plan.
This rule can also be used to specify Cache Reserve eligibility for website resources based on their size. For example, by specifying that all assets which are eligible be 100 MB and above, Cloudflare will look for eligible assets at or above 100 MB for Cache Reserve eligibility and only persistently store those assets. API configuration object name: API property name for enabling Cache Reserve: Refer to Create a cache rule via API for complete API examples.API information
"cache_reserve"
."enabled"
(boolean).API configuration example
Caching on Port (Enterprise-only)
Cloudflare supports several network ports by default, like 80 or 443. Some ports, traditionally admin ports, are supported but have caching disabled as they are used to manage sensitive information that should be ineligible for cache. Enterprise customers wanting to enable caching on these admin ports can cache on these ports by entering their desired port. API configuration property name: Refer to Create a cache rule via API for complete API examples.API information
"additional_cacheable_ports"
(array of integer values).API configuration example
Proxy Read Timeout (Enterprise-only)
Defines a timeout value between two successive read operations to your origin server. The default value can be found in the Connection limits table. If you are attempting to reduce API configuration property name: Refer to Create a cache rule via API for complete API examples.HTTP 524
errors because of timeouts from an origin server, try increasing this timeout value using the API endpoint below.API information
"read_timeout"
(integer).API configuration example
Serve stale content while revalidating
Defines if Cloudflare will serve stale content while updating the latest content from the origin server. If serving stale content is disabled, Cloudflare will not serve stale content while getting the latest content from the origin. API configuration property name: Refer to Create a cache rule via API for complete API examples.API information
"serve_stale"
> "disable_stale_while_updating"
(boolean).API configuration example
Respect Strong ETags
Turn on or off byte-for-byte equivalency checks between the Cloudflare cache and the origin server. When enabled, Cloudflare will use strong ETag header validation to ensure that resources in the Cloudflare cache and on the origin server are byte-for-byte identical. If disabled, Cloudflare converts ETag headers into weak ETag headers. API configuration property name: Refer to Create a cache rule via API for complete API examples.API information
"respect_strong_etags"
(boolean).API configuration example
Origin error page pass-through
Turn on or off Cloudflare error pages generated from error HTTP status codes sent from the origin server. If enabled, this setting enables the use of error pages issued by the origin. API configuration property name: Refer to Create a cache rule via API for complete API examples.API information
"origin_error_page_passthru"
(boolean).API configuration example
Origin Cache Control (Enterprise-only)
When this option is enabled, Cloudflare will aim to strictly adhere to RFC 7234. Enterprise customers have the ability to select if Cloudflare will adhere to this behavior. Free, Pro, and Business customers have this option enabled by default and cannot disable it. API configuration property name: Refer to Create a cache rule via API for complete API examples.API information
"origin_cache_control"
(boolean).API configuration example