Available settings
These are the settings that you can configure when creating a cache rule.
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.
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
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.
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.
When you select Eligible for cache, you can change the configuration settings described below.
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 edge TTL 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 information
API configuration object name: "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. |
Refer to Create a cache rule via API for complete API examples.
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 information
API configuration object name: "browser_ttl"
.
API values for the "mode"
property: "respect_origin"
, "override_origin"
, "bypass_by_default"
.
API values for the "default"
property (integer): values available depend on your plan. Refer to Browser Cache TTL.
Refer to Create a cache rule via API for complete API examples.
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 deception armor, Cache by device type, 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, No query parameters except and enter the parameters, or Ignore query string (also available for pay-as-you-go customers).
-
In the Headers section, you can specify header names along with their values. For custom headers, values are optional; however, for the following restricted headers, you must include one to three specific values:
accept
accept-charset
accept-encoding
accept-datetime
accept-language
referer
user-agent
To check for a header’s presence without including its value, use the Check presence of option. You can also choose whether to 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"
).
Refer to Create a cache rule via API for complete API examples.
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 information
API configuration object name: "cache_reserve"
.
API property name for enabling Cache Reserve: "eligible"
(boolean).
Refer to Create a cache rule via API for complete API examples.
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 information
API configuration property name: "additional_cacheable_ports"
(array of integer values).
Refer to Create a cache rule via API for complete API examples.
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 HTTP 524
errors because of timeouts from an origin server, try increasing this timeout value using the API endpoint below.
API information
API configuration property name: "read_timeout"
(integer).
Refer to Create a cache rule via API for complete API examples.
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 information
API configuration property name: "serve_stale"
> "disable_stale_while_updating"
(boolean).
Refer to Create a cache rule via API for complete API examples.
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 information
API configuration property name: "respect_strong_etags"
(boolean).
Refer to Create a cache rule via API for complete API examples.
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 information
API configuration property name: "origin_error_page_passthru"
(boolean).
Refer to Create a cache rule via API for complete API examples.
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 information
API configuration property name: "origin_cache_control"
(boolean).
Refer to Create a cache rule via API for complete API examples.