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.
- Access Azion Console > Edge Application.
- Click the edge application you want to configure.
- Activate the Application Accelerator module to unlock advanced cache key configurations.
- Click the Save button.
- Navigate to the Cache Settings tab.
- Click the + Cache Setting button.
- Give your cache setting a name.
Cache Expiration Policies
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.
- In Browser Cache Settings, select Override Cache Settings to determine a custom TTL value.
- Add the TTL in seconds in the Maximum TTL (seconds) field. For example:
432000
= 5 days.
In Edge 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:
- In Edge Cache Settings, select Override Cache Settings to determine a custom TTL value.
- Add the TTL in seconds in the Maximum TTL (seconds) field. For example:
864000
= 10 days.
Large File Optimization
Instead of downloading a large content file and risking timeouts or connection terminations, files can be fragmented in pieces and cached on-demand.
- In Large File Optimization, enable the switch to activate.
- 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.
Advanced cache key
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:
- In Cache by Query String, select Content varies by some Query String fields (Allowlist).
- 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:
- Enable the Query String sort switch.
You can also customize which types of requests can be cached:
- Activate the Enable caching for POST switch to cache
POST
requests. - Activate the Enable caching for OPTIONS switch to cache
OPTIONS
requests.
Next, you can determine content variation based on cookies:
- In Cache by Cookies, select Content varies by some Cookies (Allowlist).
- 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.
Adaptive delivery
If you’ve created a device group, you can segment cache keys based on the device groups you created. To do so:
- Select Content varies by some Device Groups (Allowlist).
- Click the + Add Device Group button to add a device group.
- Select the device group from the list.
- 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:
- Click the Save button.
Activating your cache setting
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.
- Navigate to the Rules Engine tab.
- Click the + Rule button.
- Give a name for your rule.
- Select Request Phase.
- Under the Criteria section, select the variable
${uri}
.
- As a comparison operator, select is equal.
- As an argument, add
/cache
. - In the Behaviors section, select Set Cache Policy from the behavior list.
- Select the new cache setting you created.
- Click the Save button.
- 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.
- Access Real-Time Manager (RTM).
- On the upper-left corner of the page, open the Products menu, represented by three horizontal lines, and select Edge Application.
- Click the edge application you want to configure.
- Activate the Application Accelerator module to unlock advanced cache key configurations.
- Navigate to the Cache Settings tab.
- Click the Add Cache Settings button.
- Give your cache setting a name.
Expiration settings
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.
- In Browser Cache Settings, select Override Cache Settings to determine a custom TTL value.
- 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:
- In CDN Cache Settings, select Override Cache Settings to determine a custom TTL value.
- Add the TTL in seconds in the Maximum TTL (seconds) field. For example:
864000
= 10 days.
Large File Optimization
Instead of downloading a large content file and risking timeouts or connection terminations, files can be fragmented in pieces and cached on-demand.
- In Large File Optimization, enable the switch to activate.
- 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.
Advanced cache key
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:
- In Cache by Query String, select Content varies by some Query String fields (Whitelist).
- 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:
- Enable the Query String sort switch.
You can also customize which types of requests can be cached:
- Activate the Enable caching for POST switch to cache
POST
requests. - Activate the Enable caching for OPTIONS switch to cache
OPTIONS
requests.
Next, you can determine content variation based on cookies:
- In Cache by Cookies, Select Content varies by some Cookies (Whitelist).
- 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.
Adaptive delivery
If you’ve created a device group, you can segment cache keys based on the device groups you created. To do so:
- Select Content varies by some Device Groups (Whitelist).
- Click the + button to add a device group.
- Select the device group from the list.
- 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:
- Click the Save button.
Activating your cache setting
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.
- Navigate to the Rules Engine tab.
- Click the Add Rule button and select Request Phase.
- Under the Criteria section, select the variable
${uri}
.
- As a comparison operator, select is equal.
- As an argument, add
/cache
. - In the Behaviors section, select Set Cache Policy from the behavior list.
- Select the new cache setting you created.
- Click the Save button.
- 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.
- 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:
- You’ll receive a response with the updated value.
- If you want to configure adaptive delivery for one of your device groups, run the following
GET
request beforehand:
- Copy the ID received in the response.
- 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:
Key | Description |
---|---|
name | Sets the string in value as a name of the cache setting. |
browser_cache_settings | Sets 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_ttl | Determines the TTL for browser cache in seconds. |
cdn_cache_settings | Sets 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_ttl | Determines the TTL for edge cache in seconds. If no headers are received from the origin, implements a default TTL value. |
cache_by_query_string | Defines whether cache should be segmented into cache keys based on query strings. For all available options, see the API documentation. |
query_string_fields | Sets 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_action | Defines whether cache should be segmented into cache keys based on device groups. |
device_group | Sets 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_sort | When 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_options | Enables caching of OPTIONS requests. |
cache_by_cookies | Defines whether cache should be segmented into cache keys based on cookies. For all available options, see the API documentation. |
cookie_names | Sets 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_post | Enables caching of POST requests. |
l2_caching_enabled | Enables caching in the tiered cache layer. You must have the Tiered Cache module active to enable this setting. |
is_slice_configuration_enabled | Enables the Large File Optimization feature. |
is_slice_edge_caching_enabled | Enables 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_enabled | Enables Large File Optimization for the tiered cache layer. You must have the Tiered Cache module active to enable this setting. |
- You’ll receive a response similar to this:
- 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:
- You’ll receive a response with the updated data.
- 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.
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.