tencent cloud

Feedback

Custom Cache Key

Last updated: 2024-01-02 10:01:16

    Feature Introduction

    When you need to point the Request URL of the same path to different files based on request parameters, cookies, or HTTP request headers, or point the Request URL with different parameters to the same file, the custom Cache Key supports customizing the Cache Key identification of resources in the node, including concatenating query strings, concatenating HTTP headers or Cookie information, etc., so that the Request URL can correctly obtain the corresponding cached resources according to different scenarios. You can learn what a Cache Key is through the Cache Key Introduction.

    Usage Scenarios

    Scenario One: The file paths accessed by users are exactly the same, but there will be version differences based on the carried query strings, HTTP request headers, and Cookie contents. The cache key of this type of file can be adjusted by customizing the Cache Key.
    Scenario Two: The content of the query string in the user's accessed URL does not affect the file content, and the files corresponding to the above requests are consistent and do not affect the file version. The cache key of this type of file can be adjusted by customizing the Cache Key.

    Directions

    Scenario One: Configure custom Cache Key for all domain names of the site

    If you need to configure a custom Cache Key for the entire connected site, or as a site-level fallback configuration, please refer to the following steps:
    1. Log in to the EdgeOne console, click on the site list in the left menu bar, and click on the site to be configured in the site list.Directions
    2. On the site details page, click on Security Acceleration > Cache Configuration/Ignore Case, find the query string card, and click on the global site settings to configure it.
    Note:
    Global configuration can only configure query strings and case-insensitive. For more comprehensive custom Cache Key configuration options, please refer to the configuration steps in Scenario Two's rule engine.
    
    
    
    The default configuration is to retain all, that is, to retain all query parameters of the original Request URL as the Cache Key. Other options are available: a. Ignore All: Ignore the entire query string; b. Retain Specified Parameters: Only retain the specified parameters in the query string; c. Ignore Specified Parameters: Only ignore the specified parameters in the query string.
    
    
    
    The default configuration is to turn off case-insensitive, that is, even if the URL content is the same, but the letter case is different, it is considered a different Cache Key. After turning on case-insensitive, different letter cases will be considered the same Cache Key.

    Scenario Two: Configure custom Cache Key for specific domain names, paths, or file extensions, etc.

    If you need to configure a custom Cache Key rule for the www.example.com domain under the site example.com to ignore all query strings, concatenate the HTTP request header My-Client-Header, and use the parameters name1 and name2 in the Cookie as the Cache Key, you can refer to the following steps for configuration:

    Directions

    1. Log in to the EdgeOne console, click on the site list in the left menu bar, and click on the site to be configured in the site list.
    2. On the site details page, click on the rule engine.
    3. On the rule engine management page, click Create Rule to enter the new rule editing page. On the rule editing page, select Host as the matching type and configure it as www.example.com.
    4. Click on the operation, and in the pop-up operation list, select the operation as Custom Cache Key;
    5. Click on Add under the Type to add the custom Cache Key type. In this example scenario, add Query String, HTTP Request Header, and Cookie for configuration and fill in the corresponding content. The complete rule configuration is as follows:
    
    
    
    6. Click Save and Publish to complete the rule configuration.

    Effective Example

    After the configuration is completed, the Cache Key is composed of URL+My-Client-Header+Cookie: Ignore all query strings, concatenate My-Client-Header, and retain the specified parameters in the Cookie.
    Then Client A request:
    URL: https://www.example.com/path/demo.jpg?key1=value1&key2=value2
    HTTP request header: Contains My-Client-Header:fruit
    Cookie: name1=yummy;name2=tasty;name3=strawberry
    And Client B request:
    URL: http://www.example.com/path/demo.JPG?key1=value1&key2=value2&key3=value3
    HTTP request header: Contains My-Client-Header:fruit
    Cookie: name1=yummy;name2=tasty;name3=blueberry
    And Client C request:
    URL: http://www.example.com/path/demo.JPG?key1=value1&key2=value2&key3=value3&key4=value4
    HTTP request header: Contains My-Client-Header:sea
    Cookie: name1=yummy;name2=tasty;name3=fish
    Requests A and B will hit the same cached resource, while C will hit another cached resource.

    Related Reference

    Description of supported header names:
    Header Type
    Description
    Custom Header
    Custom Headers.
    Name: 1 - 100 characters, consisting of digits 0 - 9, letters a - z, A - Z, and the special character -.
    Value: 1 - 1000 characters, Chinese is not supported.
    Preset Header
    Aggregated headers based on client User-Agent information:
    Client Device Type: EO-Client-Device
    Values: Mobile, Desktop, SmartTV, Tablet, or Others
    Client Operating System: EO-Client-OS
    Values: Android, iOS, Windows, MacOS, Linux, or Others
    Client Browser Type: EO-Client-Browser
    Values: Chrome, Safari, Firefox, IE, or Others
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support