Customizing Cache Keys

2024-04-28 07:19:13

Feature Overview

The cache key is a sole identifier when a file is cached on an edge POP, and there is a one-to-one relationship between the cache file and cache key. By default, the cache key is the original URL (including a query string) of the request that is sent from a client.

You can configure a custom cache key for requests that are sent using different URLs but point to the same file. This helps you increase the cache hit ratio and reduce the number of back-to-origin requests.

Application Scenario

A client requests different URLs that point to the same cached file. In such a case, you can enable the custom cache key feature to map the requests to the same file on the edge node to avoid different files from being cached, which helps reduce the back-to-origin rate.

For example, customers may set a string for hotlink protection in requesting URLs. The string may be included in the query string or a specific first-level directory. Assume that Request 1 is http://www.ctyun.cn/xxxxx/test/a.mp4, and Request 2 is http://www.ctyun.cn/yyyyy/test/a.mp4. Because the URLs are different, the edge node considers that different files are requested by default and caches different MP4 files. However, the two request URLs point to the same file because their first-level directories are strings for hotlink protection. In this case, you can customize the cache URI to set the cache key to http://www.ctyun.cn/test/a.mp4 so that only one file is cached.

Cautions

• The Cache Configuration ignores query strings when caching by default. After this feature is enabled, if the client’s request URL include multiple parameter values, e.g., Request 1: http://www.ctyun.cn/a.mp4?a=1 and Request 2: http://www.ctyun.cn/a.mp4?a=2, the cache keys corresponding to the requests are unified as: http://www.ctyun.cn/a.mp4. This way, the two requests hit the same cached file, thereby reducing the back-to-origin rate. If the ignore query strings when caching feature can meet your requirements for custom cache keys, you can enable the feature with no need to configure the custom cache parameter.

• If both the custom cache key feature and the ignore query strings when caching feature for Cache Configuration are enabled at the same time, the custom cache key feature takes prevalence.

• We recommend that you do not change your custom cache key setting. If you change the custom cache key setting after it takes effect, the cache entries that are generated based on the original custom cache key setting become invalid, which can result in a large number of back-to-origin requests.

• Custom cache keys can only be configured by enabling Static Acceleration. If it is not enabled, all files will not be cached, and there is no need to configure cache keys.

Procedure

Cache Parameter

Log in to console.

On the Acceleration Management > CDN Acceleration Configuration page, click the target domain name.

Select Static Configuration > Cache Parameters and click Edit Configuration.

Click Add to configure the cache parameters based on your requirements.


lXhEBYF4kQ1m