skip to content

Cache Rules & Keys

Cache Rules make a response eligible for cache, set its TTLs and shape its cache key. Interviewers ask how a careless rule caches a logged-in page and what Cache Deception Armor stops.

on this pageshow

explore

questions

6

In Cloudflare Cache Rules, what does the default cache key contain, and which Cache Key settings stop tracking parameters splitting the cache on each plan?

level: middleimportance: must knowfreq 55%

answer

  1. URL plus a few request headers
  2. every query string is its own entry
  3. ignore versus sort
  4. include and exclude lists are Enterprise
  5. origin scheme in the default key

basics

~20 s

The default key is the scheme, host, path and query string, plus the client's Origin header and a few override headers. Every plan can ignore or sort the query string; excluding single parameters, or keying on headers, cookies, host or user features, is Enterprise-only.

solid answer

~50 s

Cloudflare's default cache key is the full URL (scheme, host, path and query string), the client's `Origin` header, the method-override headers and a few host- and URL-override headers such as `x-forwarded-host`; cookies and `User-Agent` are not in it. Every distinct query string is a separate entry, so `utm_*` tags split one product page into many. In a Cache Rule's **Cache Key** setting, every plan gets **Ignore query string** (drop the whole query string) and **Sort query string** (only canonicalise parameter order), plus Cache Deception Armor and Cache by device type. Choosing which parameters to include or exclude, and adding headers, cookies, host or user features to the key, is **Enterprise-only**; a custom key can name up to 100 query parameters. In the default key the scheme is the origin scheme; in a custom key it is the visitor's.

go deeper

for a junior

Recall that the default key is the URL with its query string plus the Origin header, and that cookies are not in it.

for a middle

Explain Ignore query string versus Sort query string and which Cache Key parts are Enterprise-only, with the 100-parameter limit.

for a senior

Show how you would cut query-string fragmentation on a non-Enterprise zone without merging pages that differ by a parameter, and the purge cost of header or cookie keys.

for a principal

Weigh hit rate against correctness and plan cost: when an allowlist key justifies Enterprise, and when path-scoped rules are enough.

## What the default cache key holds A **cache key** is the identifier Cloudflare stores a response under; two requests with the same key share one cached copy. By default it is built from: 1. The **full URL**: the scheme, the host and the path with its query string, such as `/kettles?colour=blue&utm_source=mail`. 2. The **`Origin` request header** sent by the client, so responses for different cross-origin callers are not mixed. 3. The method-override headers `x-http-method-override`, `x-http-method` and `x-method-override`. 4. The host- and URL-override headers `x-forwarded-host`, `x-host`, `x-forwarded-scheme` (unless it is http or https), `x-original-url`, `x-rewrite-url` and `forwarded`. Cookies, `User-Agent` and `Accept-Language` are not part of it. In the default key the scheme is the **origin scheme**, the protocol Cloudflare uses to reach the origin. Moving the SSL/TLS encryption mode from Off or Flexible to Full, Full (strict) or Strict changes that scheme from HTTP to HTTPS, so every key changes and the cache effectively starts empty. In a custom key the scheme is the visitor's, and such a switch leaves keys alone. ## Why tracking parameters hurt Every distinct query string is a distinct entry. When campaign links add `utm_source`, `utm_campaign` or a referral ID, one product page becomes hundreds of entries. Each one is a miss the first time in each data center, so the hit rate falls and the origin carries load the cache should have absorbed. The aim is to take those parameters out of the key **without** dropping parameters that change the page, such as `?page=2` or `?size=m`. ## Cache Key settings by plan **Cache Key** is a setting inside a Cache Rule set to Eligible for cache (`cache_key` in the API). | Cache Key option | Free | Pro | Business | Enterprise | |---|---|---|---|---| | Cache deception armor | Yes | Yes | Yes | Yes | | Cache by device type | Yes | Yes | Yes | Yes | | Ignore query string | Yes | Yes | Yes | Yes | | Sort query string | Yes | Yes | Yes | Yes | | Query string include or exclude | No | No | No | Yes | | Headers, Cookie, Host, User features | No | No | No | Yes | Below Enterprise the query-string choice is therefore all or nothing: - **Ignore query string** drops the whole query string from the key. It is safe only on paths where no parameter changes the response, such as product images or a static landing page. - **Sort query string** (`ignore_query_strings_order`) only canonicalises order: `?a=1&b=2` and `?b=2&a=1` share an entry, but different values still split it, so it does nothing about `utm_source=mail` versus `utm_source=social`. On Enterprise the **Query string** section offers **All query string parameters**, **All query string parameters except** (an exclusion list such as `utm_source`, `utm_medium`, `utm_campaign`), **No query parameters except** (an allowlist such as `page` and `size`) and **Ignore query string**. A custom key can name at most **100** query string parameters. For a shop the allowlist is the sturdier choice: a new tracking parameter added by a marketing tool does not reopen the problem. ## The other custom key parts (Enterprise) - **Headers**: include a header's value, or only check that it is present. Restricted headers such as `accept`, `accept-language` and `user-agent` must be given explicit values. `cookie`, `host`, any `cf-` header and headers such as `range` or `if-none-match` cannot be added, and `Origin` is the only default header you can exclude. - **Cookie**: include a cookie's value or check for its presence; Cloudflare's own `__cf` cookies cannot be used. - **Host**: Use original host, or Resolved host, which follows an Origin Rule's DNS record override. - **User**: device type (mobile, desktop or tablet), country, and the first language in `Accept-Language`. Each part you add multiplies the entries per URL, so add one only when the response truly differs by it. Separately, a Cache Rule's **Vary** setting, on every plan, lets request headers that the origin lists in its `Vary` response join the key; how `Vary` itself works is covered with HTTP caching. ## Side effects to plan for - A custom key that includes headers or cookies stops dashboard single-file purge from finding the entry; clearing it then takes an API purge that sends the same values, or a broader purge method. - Prefetch always uses the default cache key, so it does not fill entries stored under a custom key. - With URL normalization on, also enable **Normalize URLs to origin** when you customise keys, so the URL in the key matches what the origin receives. - Cloudflare Trace shows, for a cached request, exactly which cache key properties were used.

  • On a Business zone, how would you stop utm tags splitting product pages without breaking ?page=2 listings?
    Below Enterprise the Cache Key cannot drop single parameters, so split by path. Give product detail pages and images a Cache Rule with Ignore query string, because no parameter changes them, and leave paginated listing pages on the full query string, accepting some splitting there. An Enterprise zone could instead use No query parameters except with `page` and `size`.
  • Why does switching from Flexible to Full (strict) cause a burst of cache misses on a zone with default keys but not with a custom key?
    The default key holds the origin scheme, and Full (strict) makes Cloudflare reach the origin over HTTPS instead of HTTP, so every key changes and nothing already stored matches. A custom key holds the visitor's scheme instead, which the encryption mode does not change, so existing entries keep matching.

  • Sort query string removes tracking parameters such as utm_source from the cache key.
  • Any plan can exclude single query parameters from the key in a Cache Rule.
  • Cloudflare's default cache key includes cookies, so each signed-in user gets a separate copy.
  • Adding the session cookie to the cache key costs nothing in hit rate.
  • Ignore query string is always safe because the origin reads parameters anyway.

Assumes Cloudflare as of 2026-10-10: Ignore query string and Sort query string are on every plan while the other custom key parts stay Enterprise-only, and since July 2026 a Cache Rule's Vary setting, on every plan, can add the headers an origin lists in Vary to the key.

open as a page

In Cloudflare Cache Rules, how do you make a shop's anonymous HTML product pages cacheable, and what do Edge TTL and Browser TTL change?

level: middleimportance: must knowfreq 65%

basics

~20 s

Create a Cache Rule whose expression matches only the product paths and set it to Eligible for cache, which makes HTML cacheable. Edge TTL decides how long Cloudflare's edge keeps a copy; Browser TTL decides the lifetime sent to visitors' browsers.

open as a page

A shop's Cloudflare Cache Rule makes the whole hostname Eligible for cache with an Edge TTL ignoring Cache-Control; customers see others' account pages and sign-ins fail. Why, and what fixes it?

level: seniorimportance: must knowfreq 55%

basics

~20 s

The rule also matched account and login pages; its override Edge TTL ignored private, so Cloudflare stripped Set-Cookie and shared one customer's page. Narrow it, add a later Bypass cache rule on personal paths and the session cookie, then purge.

open as a page

When a shop moves caching Page Rules to Cloudflare Cache Rules, how do stacking, last-match-wins and Eligible for cache's Cache Everything change the result?

level: middleimportance: should knowfreq 40%

basics

~20 s

Page Rules apply only the highest-priority match; Cache Rules all apply in order and the last match wins shared settings. Eligible for cache also turns on Cache Everything, so standard caching needs a Bypass-all rule followed by an eligible rule for default extensions.

open as a page

A security review of a shop behind Cloudflare finds /account/orders/receipt.css returns a customer's order page; what does Cache Deception Armor stop here, and what else must change?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Cache Deception Armor, a Cache Key setting in a Cache Rule, skips caching when the Content-Type does not match the URL's extension, so the HTML behind .css is not stored. Overrides can defeat it: also bypass account paths and return 404 there.

open as a page

As the lead for a shop on Cloudflare, what would you let Cache Rules cache, and who may change those rules and how?

level: principalimportance: should knowfreq 30%

basics

~20 s

Make caching an allowlist: eligible rules only for catalogue paths and static files, a final bypass rule for personal paths and session cookies, respect_origin on HTML. Limit who can edit Cache Rules, the Firewall role included, and review changes as code.

open as a page