You can create rules based on different parts of a user request, such as the query string, HTTP request header, or cookie, to generate custom cache keys. This feature unifies the cache key for a class of requests that access the same file. This prevents requests for the same file from being cached as different files because of varying request parameters. As a result, the cache hit rate increases, and both response time and bandwidth consumption are reduced.
Background information
The custom cache key feature does not modify the back-to-origin URL. It only modifies the cache identity of the request. This ensures that the back-to-origin request is consistent with the client request.
A cache key is the unique identifier for a file cached on an ESA point of presence (POP). Each file cached on a POP has a unique cache key. By default, the cache key is the complete URL of the client request, including parameters.
Use cases
Procedure
After you add a rule, when a user requests a resource, ESA matches and executes rules sequentially based on the rule execution priority.
In the ESA console, choose Websites. In the Website column, click the target site.
In the navigation pane on the left, choose .
Click Create Rule and enter a Rule Name.
In the If requests match... section, configure the conditions that a request must match. For more information, see Composition of a rule expression.
In the Cache Eligibility section, set Cache Eligibility to Eligible for Cache.
In the Custom Cache Keys section, click Configure, and set the following parameters.

Parameter
Description
Sort Query Strings
Specifies whether to enable the Sort Query String feature.
Query String
Specifies whether to remove the
?and the subsequent query string from the request URL.HTTP Request Header
Include Header Names and Their Values: Adds the specified HTTP request header names and their values to the Cachekey.
Check Presence of: Checks whether the specified HTTP request headers exist. If they exist, their names are added to the Cachekey.
Cookie
Include Cookie Names and Their Values: Adds the specified cookie parameter names and their values to the Cachekey.
Check Presence of: Checks whether the specified cookie parameters exist. If they exist, their names are added to the Cachekey.
User
Device Type: Identifies the client type based on the
User-Agentinformation of the client and then generates a Cachekey based on the client type.Country/Region: Identifies the country or region of the client based on the client IP address and then generates a Cachekey based on the country or region.
Language: Identifies the client language based on the
Accept-Languageinformation in the client request and then generates a Cachekey based on the language type.
Cache Deception Defense
Defends against web cache deception attacks while allowing static content to be cached.
Click OK.
Configuration examples
Example scenario |
|
Feature configuration |
|
Generated Cachekey | The Cachekey fragments generated for each parameter are:
Therefore, the final Cachekey is a concatenation of these fragments: |
References
Rule-related features vary in execution priority, rule behavior, and configuration scope. For more information, see How ESA rules take effect.
