All Products
Search
Document Center

Edge Security Acceleration:Create custom cache keys

Last Updated:Sep 19, 2024

You can create custom cache keys based on different parts of requests, such as the query string, HTTP request headers, or cookies. This way, you can set a cache key for a type of requests that are destined for the same file to prevent the file from being cached as different files. This increases the cache hit ratio and reduces origin requests, response time, and bandwidth usage.

Background information

  • Custom cache keys do not alter origin URLs, but only modify the cache identifiers in requests. Requests that are redirected to origin servers and that are sent by clients are intended for the same content.

  • A cache key is the unique ID of a file that is cached on a point of presence (POP). Each file that is cached on POPs has a cache key. By default, the cache key of a file is the URL in the request that is sent to retrieve the file. The URL contains parameters.

Scenarios

Scenario 1: Identical cache keys

The URLs in requests may contain complex parameters. Therefore, even if the requests are sent to retrieve the same content, due to the variation of URL parameters, POPs consider that the requests are sent to retrieve different resources and then cache resources for all requests. As a result, a large number of requests are routed to the origin server.

image

You can use the custom cache key feature to ignore query strings and set a cache key for a type of requests to reduce the number of origin requests.

image

Scenario 2: Different cache keys

The requests contain the same URL. In this case, DCDN considers that the requests are sent to retrieve the same resource. However, in fact, the client OSs are specified in the client field of the HTTP header in the requests. The requests may be sent to retrieve different files.

image

You can create two cache keys, include the values of the client field in the cache keys, and then use the cache keys to distinguish the requests.

image

Procedure

  1. Log on to the ESA console.

  2. In the left-side navigation pane, click Websites.

  3. On the Websites page, find the website that you want to manage, and click the website name or View Details in the Actions column.

  4. In the left-side navigation tree, choose Caching > Cache Rules.

  5. Click Create Rule and specify the Rule Name parameter.

  6. In the If requests match... section, specify the conditions for matching incoming requests. For more information about how to configure a rule, see Overview.

  7. In the Bypass Cache section, specify whether to bypass cache. For more information, see Bypass cache.

  8. In the Custom Cache Keys section, click Configure and configure the following parameters.

    image

    Parameter

    Description

    Sort Query Strings

    Specify whether to sort query strings. For more information, see Sort query strings.

    Query String

    Specify whether to remove the question mark (?) and query string that follows the question mark (?) from the request URL. For more information, see Query string.

    HTTP Request Header

    • Include Header Names and Their Values: adds specific HTTP request headers and their values to the cache key.

    • Check Presence of: checks whether the specific HTTP request headers exist and adds the HTTP headers to the cache key if the HTTP request headers exist.

    Cookie

    • Include Cookie Names and Their Values: adds specific cookie names and their values to the cache key.

    • Check Presence of: checks whether the specific cookies exist and adds the cookies to the cache key if the cookies exist.

    User

    • Device Type: identifies the client type based on the User-Agent header and generates a cache key based on the client type. Valid values:

    • Country/Region: identifies the country or region where the client resides based on the client IP address and generates a cache key based on the country or region.

    • Language: identifies the client language based on the Accept-Language header in the request and generates a cache key based on the language.

  9. Click OK.

Configuration example

Scenario

  • Request URL: http://www.example.com/image.jpg?key123=321&key456=654

  • Request headers:

    • name123:321

    • name456:654

    • User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

    • Accept-Language:zh-CN

  • The client uses an IP address that is provided by China Telecom.

Feature configurations

  • Query String: Ignore the key456 parameter.

  • HTTP Request Header:

    • Include Header Names and Their Values: name123.

    • Check Presence of: name456.

  • User:

    • Select Device Type, Country/Region, and Language.

image

Generated cache key

The following cache key fragments are generated for the parameters:

  • http://www.example.com/image.jpg?key123=321

  • name123:321

  • name456

  • desktop

  • CN

  • Accept-Language:zh-CN

Therefore, the concatenated cache key is http://example.com/image.jpg?key123=321name123:321name456desktopCNAccept-Language:zh-CN.