Cache keys

How the edge decides that two requests share a cached object, how query strings enter the key and which Vary headers it supports.

On this page

The cache key identifies a cached object. Two requests with the same key get the same cached response.

What's in the key

PartHow it's normalized
SiteEach proxied name is its own site, so names never share objects.
HostLower case, without port or trailing dot.
Path%XX escapes in upper case, escapes of unreserved characters decoded, . and .. segments resolved. // is kept and reserved characters stay as sent (%2F and / are different). The same path is sent to the origin.
Query stringAccording to the caching level.
VariantOnly when the origin sends a supported Vary.

Cookies, the Authorization header and the OpenWAF challenge and access-gate cookies never enter the key. Keys longer than 4 KB aren't cached.

Changing the query settings of a site or its rules changes its keys, which acts like a purge for that site.

Query string

cache.query.mode, called Caching level in the dashboard, decides which part of the query string goes into the key:

ModeDashboardKey
all (default)Standard: the whole query stringThe whole query, exactly as sent. ?v=1 and ?v=2 are different objects.
ignoreIgnore query string (static files)No query, but only for the default static extensions. Rule-eligible paths keep their query.
noneNo query string: cache only requests without oneRequests with a query aren't cached at all (DYNAMIC).
includeOnly these parametersOnly the parameters in cache.query.params.
excludeAll parameters except theseEvery parameter except those in cache.query.params, for example utm_*, fbclid, gclid.

A trailing * in params matches a prefix. With cache.query.sort set to true, the parameters are sorted, so ?b=1&a=2 and ?a=2&b=1 share one object. A cache rule can set its own query policy for the requests it matches.

Vary

The edge stores at most one variant per value of the supported Vary headers:

Vary headerHandling
Accept-EncodingDoesn't split the cache: one copy, decompressed on the fly for visitors who need it.
AcceptOnly for image/* responses. Normalized to avif, webp or other, enough for image optimizers.
OriginNormalized to scheme://host[:port]. Also applied when the response has an Access-Control-Allow-Origin other than *, even without Vary: Origin, so one site's CORS answer is never served to another.
Anything else, including *, Cookie and AuthorizationThe response isn't stored (BYPASS).

A cache rule can list request headers in vary_bypass_if_present (for example the RSC and Next-Router-* headers of Next.js). A request carrying any of them skips the cache, and a Vary from the origin that names them no longer prevents storing the normal version. See Cache rules.

Headers removed before the origin

On eligible requests the edge removes headers that aren't in the key but that an origin might reflect into the page, a common cache-poisoning vector:

X-Original-URL, X-Rewrite-URL, X-HTTP-Method-Override, X-HTTP-Method, X-Method-Override, X-Host, X-Forwarded-Scheme, X-Forwarded-Server and X-Forwarded-Port.

Last updated:

↑↓ to navigate↵ to openesc to close