A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.cloudflare.com/cache/how-to/cache-keys/ below:

Cache Keys · Cloudflare Cache (CDN) docs

A Cache Key is an identifier that Cloudflare uses for a file in our cache, and the Cache Key Template defines the identifier for a given HTTP request.

A default cache key includes:

  1. Full URL:
  2. Origin header sent by client (for CORS support).
  3. x-http-method-override, x-http-method, and x-method-override headers.
  4. x-forwarded-host, x-host, x-forwarded-scheme (unless http or https), x-original-url, x-rewrite-url, and forwarded headers.

Custom cache keys let you precisely set the cacheability setting for any resource. They provide the benefit of more control, though they may reduce your cache hit rate and result in cache sharding:

  1. Log in to your Cloudflare dashboard ↗, and select your account and domain.
  2. Go to Caching > Cache Rules.
  3. Select Create rule.
  4. Under When incoming requests match, define the rule expression.
  5. Under Then, in the Cache eligibility section, select Eligible for cache.
  6. Add the Cache Key setting to the rule and select the appropriate Query String setting.
  7. You can also select settings for Headers, Cookie, Host, and User.
  8. To save and deploy your rule, select Deploy. If you are not ready to deploy your rule, select Save as Draft.

Note

When URL normalization is enabled, we recommend also enabling Normalize URLs to origin, especially if you are setting custom cache keys or using cache by device type, which also modifies the cache key. This helps ensure the URL in the cache key matches the URL sent to the origin, preventing cache poisoning and ensuring consistent behavior.

There are a couple of common reasons to change the Cache Key Template. You might change the Cache Key Template to:

Impact of SSL settings on Cache behavior

Cloudflare's $scheme variable plays a key role in caching behavior, but its meaning varies depending on the cache key type:

For example, with Flexible SSL, Cloudflare always connects to the origin over HTTP, regardless of whether the visitor uses HTTP or HTTPS. This results in the same cache key for both protocols under the default configuration.

Be aware that changes in the SSL setting can lead to cache invalidation when using the default cache key:

Understanding how $scheme interacts with your caching configuration is essential when modifying SSL modes to avoid unexpected cache behavior.

Cache Level: Ignore Query String

A Cache Level of Ignore Query String creates a Cache Key that includes all the elements in the default cache key, except for the query string in the URI that is no longer included. For instance, a request for http://example.com/file.jpg?something=123 and a request for http://example.com/file.jpg?something=789 will have the same cache key, in this case.

The following fields control the Cache Key Template.

The query string controls which URL query string parameters go into the Cache Key. You can include specific query string parameters or exclude them using the respective fields. When you include a query string parameter, the value of the query string parameter is used in the Cache Key.

If you include the query string foo in a URL like https://www.example.com/?foo=bar, then bar appears in the Cache Key. Exactly one of include or exclude is expected.

Headers control which headers go into the Cache Key. Similar to Query String, you can include specific headers or exclude default headers.

When you include a header, the header value is included in the Cache Key. For example, if an HTTP request contains an HTTP header like X-Auth-API-key: 12345, and you include the X-Auth-API-Key header in your Cache Key Template, then 12345 appears in the Cache Key.

In the Check if header contains section, you can add header names and their values to the cache key. For custom headers, values are optional, but for the following restricted headers, you must include one to three specific values:

To check for the presence of a header without including its actual value, use the Check presence of option.

Currently, you can only exclude the Origin header. The Origin header is always included unless explicitly excluded. Including the Origin header ↗ in the Cache Key is important to enforce CORS ↗.

Additionally, you cannot include the following headers:

Host determines which host header to include in the Cache Key.

Like query_string or header, cookie controls which cookies appear in the Cache Key. You can either include the cookie value or check for the presence of a particular cookie.

You cannot include cookies specific to Cloudflare. Cloudflare cookies are prefixed with __cf, for example, __cflb

User feature fields add features about the end-user (client) into the Cache Key.

Cache keys options availability varies according to your plan.

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

No

No

No

Yes

Headers

No

No

No

Yes

Cookie

No

No

No

Yes

Host

No

No

No

Yes

User features

No

No

No

Yes

The Prefetch feature is not compatible with the custom cache keys. With Cache Rules, the custom cache key is used to cache all assets. However, Prefetch always uses the default cache key. This results in a key mismatch.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4