- 30 Jun 2024
- 5 Minutes to read
- Print
- PDF
Cache Key Management
- Updated on 30 Jun 2024
- 5 Minutes to read
- Print
- PDF
Overview
The CDN assigns a unique identifier (a cache key) to each object in the CDN cache. The cache key is generated from the URI of the content request. Use the Cache Key Management rule to customize cache key generation.
Configure a basic Cache Key Management rule to exclude path segments or query parameters from the cache key. When you use the Basic feature to configure the rule, the hostname is added implicitly to the cache key to allow for the unique identification of objects across different hosts.
The Advanced feature lets you define a more complex rule. For example, you can use the advanced feature to set conditions on the query parameters, to share cached objects across multiple different hosts, and to define a custom MEL expression.
Configure the Rule
Here, we'll describe how to configure the rule with the Delivery Service Management UI.
API Users may choose to build the site configuration offline.
Basic
With both the UI and the API, you can set basic rules (exclude path segments, include/exclude all or specified query parameters from the cache key).
To configure a basic Cache Key Management rule:
In the Select Rule dialog, choose Cache Key Management.
On the Basic tab, set the cache key management rules.
Exclude path pattern - This is an optional field you can use to exclude path segments from the cache key.
You can use wildcards to define a pattern:Wildcard Description * represents any sequence of alphanumeric or '/' characters. ? represents exactly one character. When there is a match, the path segment is excluded from the cache key. If there is not a match, the full URI path is used to construct the key.
For example,
/userid*/
would exclude the userid segment of the request URL from the cache key.Include all query strings
- Toggle On to include all URL query parameters in the cache key.
- Toggle Off if you want to exclude some or all query parameters. The Include query strings field is enabled. Use it to exclude all query parameters or specify the query parameters to include.
Include query strings
- First, toggle the Include all query strings feature to Off, to enable this field.
- To exclude all query parameters, leave this field blank.
- To include selected query parameters only, enter the parameter names in this field. (You can enter multiple values separated by commas.)
For example:version,timestamp
adds the version and timestamp to the cache key.
Note that the hostname is implicitly added to the cache key.
Select Add Rule.
Advanced
You can configure a more complex rule by building a MEL expression.
To configure an advanced cache key management rule:
In the Select Rule dialog, choose Cache Key Management.
In the Cache Key Management Rule dialog, select Advanced.
Use the UI features in this tab to generate the MEL expression or write a MEL expression directly in the Advanced Cache Key field.
Include Host Name - Toggle on or off.
- On means the CDN will always include the hostname when generating the cache key. The hostname allows for the unique identification of objects across different hosts.
- Off means the hostname is excluded from the cache key. Use this option if you want to share cached objects across multiple different hosts.
Exclude Path Pattern - If you want to exclude certain path segments from the key, such as the user id, toggle this option on and then enter the pattern. Wildcards are supported.
For example,/userid*/
Query Params - Select an option from the menu to specify whether all or only some query parameters will be included or excluded from the cache key. Then if relevant, specify the parameter or multiple parameters separated by commas, and press Enter.
You can enter query parameter names or values.Example Description version Adds the version to the cache key version=1.0 Adds the version to the cache key if the version value is 1.0. version=2.* Adds the version to the cache key if the version is 2.<>. Headers - Select an option from the menu to specify if headers will be added to the cache key. Then if relevant, specify the header/s to be included.
For example,Accept-Encoding
Select Generate MEL. Note that it is possible to generate multiple MEL expressions (although only a single expression can be added to the site configuration). You can modify any of the MEL expressions directly in the Advanced Cache Key text box.
Select Add Rule. If you defined multiple MEL expressions, make sure the one you want to add to your site configuration is displayed in the Advanced Cache Key field when you select Add Rule.
SVTA Components
When you configure Cache Key Management on the Basic tab and save the configuration version, the MI.Cache component is added to the JSON configuration.
If you configure the rule on the Advanced tab, the MI.ComputedCacheKey component is added to the JSON configuration.
Cache Key Management (MI.Cache)
Note when cache key management is configured with the MI.Cache object, the hostname is implicitly added to the cache key.
This example instructs the CDN to use the entire path but no query parameters.
{
"generic-metadata-type": "MI.Cache",
"generic-metadata-value": {
"exclude-path-pattern": "",
"include-query-strings": []
}
}
"exclude-path-pattern": ""
No path segments are specified, so the cache key will use the entire path.
"include-query-strings": []
No query strings are specified, so the cache key will exclude all query parameters.
In the following example, "include-query-strings" is absent, so all query parameters are included.
{
"generic-metadata-type": "MI.Cache",
"generic-metadata-value": {
"exclude-path-pattern": ""
}
}
This example instructs the CDN to exclude the userid (a path segment of the request URL) from the cache key and to add the version (a query parameter of the request URL) to the cache key. (Any other query parameter in the request URL is excluded from the cache key.)
{
"generic-metadata-type": "MI.Cache",
"generic-metadata-value": {
"exclude-path-pattern": "/userid*/",
"include-query-strings": [
"version"
]
}
}
Advanced Cache Key Management (MI.ComputedCacheKey)
When you create a more complex Cache Key Management rule with the Advanced feature, the MI.ComputedCacheKey object that includes a MEL expression is added to the site configuration.
{
"generic-metadata-type": "MI.ComputedCacheKey",
"generic-metadata-value":{
"expression": "<MEL Expression>"
}
}
The MEL expression in this example instructs the CDN to use the hostname and the rightmost path segment (-1), (the filename) to create the cache key.
{
"generic-metadata-type": "MI.ComputedCacheKey",
"generic-metadata-value": {
"expression": "req.h.host . '&' . path_element(req.uri.path , -1) "
}
}
In this case, these URIs would generate the same cache key because they share the same hostname and rightmost path segment values.
example.com/path/to/file-12345.mp4
example.com/another/path/to/file-12345.mp4