How to tune your cache settings

Leverage the capabilities of Edge Cache to configure your edge application’s cache policies, including expiration values at the edge or browser level, large file optimization to break large files into smaller chunks, and cache key segmentation based on query strings or cookies.


When you first create an edge application, a cache setting variable will be created and activated by default. This guide will show you how to create and activate a brand new cache setting instance.

  1. Access Azion Console.
  2. On the upper-left corner of the page, open the Products menu, represented by three horizontal lines, and select Edge Application.
  3. Click the edge application you want to configure.
  4. Activate the Application Accelerator module to unlock advanced cache key configurations.
  5. Navigate to the Cache Settings tab.
  6. Click the Add Cache Settings button.
  7. Give your cache setting a name.

You can customize the cache Time To Live (TTL) in browsers and at the edge. This data is sent in requests and responses through the Cache-Control and Expires HTTP headers.

  1. In Browser Cache Settings, select Override Cache Settings to determine a custom TTL value.
  2. Add the TTL in seconds in the Maximum TTL (seconds) field. For example: 432000 = 5 days.

In CDN Cache Settings, you can determine whether the edge should abide by the values sent in the Cache-Control and Expires headers.

You can choose to keep Honor Origin Cache Headers selected to respect the TTL values sent in the headers by the origin or the application itself.

If your application isn’t sending Cache-Control and Expires headers or the values aren’t set correctly, you can determine a default maximum TTL for the cache to be maintained at the edge in the Default TTL (seconds) field. If your application is sending these values, to override them:

  1. In CDN Cache Settings, select Override Cache Settings to determine a custom TTL value.
  2. Add the TTL in seconds in the Maximum TTL (seconds) field. For example: 864000 = 10 days.

Instead of downloading a large content file and risking timeouts or connection terminations, files can be fragmented in pieces and cached on-demand.

  1. In Large File Optimization, enable the switch to activate.
  2. The Edge Cache layer is already selected by default. If you have the Tiered Cache module activated, you can also enable this feature for the tiered cache layer.

The next step is to customize how your content will be cached at the edge through cache keys. You can choose to segment cache keys based on query string or cookies.

To determine content variation in cache:

  1. In Cache by Query String, select Content varies by some Query String fields (Whitelist).
  2. In Query String fields, add the value city.

When a request is made to an application URL xxxxxxxxxx.map.azionedge.net/page?city=12345, the cache key for this URL will be different from cache keys made to xxxxxxxxxx.map.azionedge.net/page and any other queries appended to the URL.

To disregard the order of the data sent in the query string and keep objects with the same query string values as a single cache key:

  1. Enable the Query String sort switch.

You can also customize which types of requests can be cached:

  1. Activate the Enable caching for POST switch to cache POST requests.
  2. Activate the Enable caching for OPTIONS switch to cache OPTIONS requests.

Next, you can determine content variation based on cookies:

  1. In Cache by Cookies, Select Content varies by some Cookies (Whitelist).
  2. In Cookie names, add the value cookie_name.

When a request is made to an application and the response from the origin sends a Set-Cookie header, the objects in the Cookie request header that contain the name cookie_name, regardless of value, will be considered as a different object in cache from other requests.

If you’ve created a device group, you can segment cache keys based on the device groups you created. To do so:

  1. Select Content varies by some Device Groups (Whitelist).
  2. Click the + button to add a device group.
  3. Select the device group from the list.
  4. Repeat steps 15 and 16 for every device group you wish to specify a different cache key.

Once you’ve finished configuring your cache setting:

  1. Click the Save button.

The cache settings page now lists the newly created instance. However, this new cache setting isn’t active in your application. You need to define what will trigger the implementation of the cache policies in your application. For this, you can use your edge application’s Rules Engine.

The instructions below will help you create a rule in which any request from your users to xxxxxxxxxx.map.azionedge.net/cache will apply the cache setting you created.

  1. Navigate to the Rules Engine tab.
  2. Click the Add Rule button and select Request Phase.
  3. Under the Criteria section, select the variable ${uri}.
  1. As a comparison operator, select is equal.
  2. As an argument, add /cache.
  3. In the Behaviors section, select Set Cache Policy from the behavior list.
  4. Select the new cache setting you created.
  5. Click the Save button.
  6. Wait a few minutes for the changes to propagate.

To verify how your content is being cached, you can verify application cache indicators using Modheader for Google Chrome.


  1. Run the following PATCH request in your terminal, replacing [TOKEN VALUE] with your personal token and the <edge_application_id> variable with your edge application ID to activate the Application Accelerator module:
Terminal window
curl --location --request PATCH 'https://api.azionapi.net/edge_applications/<edge_application_id>' \
--header 'Accept: application/json; version=3' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token [TOKEN VALUE]' \
--data '{
"application_acceleration": true
}'
  1. You’ll receive a response with the updated value.
  2. If you want to configure adaptive delivery for one of your device groups, run the following GET request beforehand:
Terminal window
curl --location 'https://api.azionapi.net/edge_applications/<edge_application_id>/device_groups' \
--header 'Accept: application/json; version=3' \
--header 'Authorization: Token [TOKEN VALUE]'
  1. Copy the ID received in the response.
  2. Run the following POST request in your terminal, replacing [TOKEN VALUE] with your personal token, the <edge_application_id> variable with your edge application ID, and the <device_group_id> with the ID of the device group from the previous response, if needed:
Terminal window
curl --location 'https://api.azionapi.net/edge_applications/<edge_application_id>/cache_settings' \
--header 'Accept: application/json; version=3' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token [TOKEN VALUE]' \
--data '{
"name": "/cache O60 O13660 Wcity Wcookie_name Wdg POST OPTIONS SLICE",
"browser_cache_settings": "override",
"browser_cache_settings_maximum_ttl": 60,
"cdn_cache_settings": "override",
"cdn_cache_settings_maximum_ttl": 13660,
"cache_by_query_string": "whitelist",
"query_string_fields": [
"city"
],
"adaptive_delivery_action": "whitelist",
"device_group": [
<device_group_id>
],
"enable_query_string_sort": false,
"enable_caching_for_options": true,
"cache_by_cookies": "whitelist",
"cookie_names": [
"cookie_name"
],
"enable_caching_for_post": true,
"l2_caching_enabled": false,
"is_slice_configuration_enabled": true,
"is_slice_edge_caching_enabled": true,
"is_slice_l2_caching_enabled": false
}'
KeyDescription
nameSets the string in value as a name of the cache setting.
browser_cache_settingsSets the string in value as the policy selected for browsers in relation to the TTL values sent in the Cache-Control or Expires headers. When "honor", cache TTL directives received from the origin are implemented. When "override", allows you to determine the browser cache TTL through browser_cache_settings_maximum_ttl.
browser_cache_settings_maximum_ttlDetermines the TTL for browser cache in seconds.
cdn_cache_settingsSets the string in value as the policy selected for the edge in relation to the TTL values sent in the Cache-Control or Expires headers. When "honor", cache TTL directives received from the origin are implemented. When "override", allows you to determine the edge cache TTL through cdn_cache_settings_maximum_ttl.
cdn_cache_settings_maximum_ttlDetermines the TTL for edge cache in seconds. If no headers are received from the origin, implements a default TTL value.
cache_by_query_stringDefines whether cache should be segmented into cache keys based on query strings. For all available options, see the API documentation.
query_string_fieldsSets the strings listed as the keys of queries that should be maintained as the same cache key or segmented into separate cache keys.
adaptive_delivery_actionDefines whether cache should be segmented into cache keys based on device groups.
device_groupSets the IDs listed as the device groups that should be maintained as the same cache key or segmented into separate cache keys.
enable_query_string_sortWhen enabled, a single cache key is generated for URLs with the same query strings regardless of the order in which they are grouped.
enable_caching_for_optionsEnables caching of OPTIONS requests.
cache_by_cookiesDefines whether cache should be segmented into cache keys based on cookies. For all available options, see the API documentation.
cookie_namesSets the strings listed as the names of cookies that should be maintained as the same cache key or segmented into separate cache keys.
enable_caching_for_postEnables caching of POST requests.
l2_caching_enabledEnables caching in the tiered cache layer. You must have the Tiered Cache module active to enable this setting.
is_slice_configuration_enabledEnables the Large File Optimization feature.
is_slice_edge_caching_enabledEnables Large File Optimization for the edge. If is_slice_configuration_enabled is set to true, this property must also be set to true.
is_slice_l2_caching_enabledEnables Large File Optimization for the tiered cache layer. You must have the Tiered Cache module active to enable this setting.
  1. You’ll receive a response similar to this:
{
"results": {
"id": <cache_settings_id>,
"name": "/cache O60 O13660 Wcity Wcookie_name Wdg POST OPTIONS SLICE",
"browser_cache_settings": "override",
"browser_cache_settings_maximum_ttl": 60,
"cdn_cache_settings": "override",
"cdn_cache_settings_maximum_ttl": 13660,
"cache_by_query_string": "whitelist",
"query_string_fields": [
"city"
],
"enable_query_string_sort": true,
"cache_by_cookies": "whitelist",
"cookie_names": [
"cookie_name"
],
"adaptive_delivery_action": "whitelist",
"device_group": [
<device_group_id>
],
"enable_caching_for_post": true,
"l2_caching_enabled": false,
"is_slice_configuration_enabled": true,
"is_slice_edge_caching_enabled": true,
"is_slice_l2_caching_enabled": false,
"slice_configuration_range": 1024,
"enable_caching_for_options": true,
"enable_stale_cache": false,
"l2_region": null
}
}
  1. Run the following POST request in your terminal, replacing [TOKEN VALUE] with your personal token, the <edge_application_id> variable with your edge application ID, and the <cache_setting_id> variable with the cache setting ID received in the response:
Terminal window
curl --location 'https://api.azionapi.net/edge_applications/<edge_application_id>/rules_engine/request/rules' \
--header 'Accept: application/json; version=3' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token [TOKEN VALUE]' \
--data '{
"name": "Set cache setting /cache",
"behaviors": [
{
"name": "set_cache_policy",
"target": "<cache_setting_id>"
}
],
"criteria": [
[
{
"variable": "${uri}",
"operator": "is_equal",
"conditional": "if",
"input_value": "/cache"
}
]
]
}'
  1. You’ll receive a response with the updated data.
  2. Wait a few minutes for the changes to propagate.

To verify how your content is being cached, you can verify application cache indicators using Modheader for Google Chrome.


Contributors