How to configure Advanced Cache Key for Edge Application
Azion Application Accelerator enables access to the Advanced Cache Key feature, which allows you to create cache rules based on URL Query Strings and Cookies. You can apply these rules to a dynamic application using Rules Engine.
To activate Advanced Cache Key for an edge application:
- Access Azion Console > Edge Application.
- Select the application you want to configure or create a new one.
- On the Main settings tab, in the Modules section, enable the Application Accelerator switch.
- Click the Save button.
- Access Real-Time Manager (RTM).
- On the upper-left corner of the page, select Products menu, represented by three horizontal lines.
- Under BUILD, click Edge Application.
- Select the application you want to configure or create a new one.
- On the Main settings tab, under the Modules section, enable the Application Accelerator switch.
- Click the Save button.
Creating advanced cache rules for dynamic content based on Query Strings
To illustrate the use of Advanced Cache Key based on Query Strings, assume your application has the following URL: domain.com/page?city=city_name
.
The /page
URI has an API, called by the Query String ?city=city_name
that lists the content depending on the user’s city. The content of the page is automatically updated every five minutes.
In order to match the cache TTL with the update time of the content called by the city
field:
- Access Azion Console > Edge Application.
- Select the application and ensure Application Accelerator is active.
- Click on the Cache Settings tab.
- Click on the + Cache Setting button.
- Give your setting an easy-to-remember name.
- Both in the Browser Cache Settings and Edge Cache Settings sections:
- Check the option Override Cache Settings.
- Set the Maximum TTL (seconds) to
300
(5 minutes).
- In the Advanced Cache Key section, define your custom Cache by Query String as follows:
- Select the option Content varies by some Query String fields (Allowlist).
- In Query String fields, enter the value
city
.
- Click the Save button.
Now, there’s a cache policy object with the Query String for city
that can be activated in Rules Engine as follows:
- Click on the Rules Engine tab.
- Click the + Rule button.
- Give a name to your rule.
- Select the Request Phase.
- In the Criteria section, set the criteria that triggers the behavior every time the URI
/page
is accessed as follows:- If
${uri}
starts with/page
- If
- In the Behaviors section:
- Select the Set Cache Policy behavior.
- Select the cache setting you created for the
city
Query String.
- Click the Save button.
- Access Real-Time Manager (RTM).
- On the upper-left corner of the page, select Products menu, represented by three horizontal lines.
- Under BUILD, click Edge Application.
- Select the application and ensure Application Accelerator is active.
- Click on the Cache Settings tab.
- Click on the Add Cache Settings button and give your setting an easy-to-remember name.
- Both in the Browser Cache Settings and CDN Cache Settings sections:
- Check the option Override Cache Settings.
- Set the Maximum TTL (seconds) to
300
(5 minutes).
- In the Advanced Cache Key section, define your custom Cache by Query String as follows:
- Select the option Content varies by some Query String fields (Whitelist).
- In Query String fields, enter the value
city
.
- Click the Save button.
Now, there’s a cache policy object with the Query String for city
that can be activated in Rules Engine as follows:
- Click on the Rules Engine tab.
- Click the Add Rule button and select the Request Phase.
- In the Criteria section, set the criteria that triggers the behavior every time the URI
/page
is accessed as follows:- If
${uri}
starts with/page
- If
- In the Behaviors section:
- Select the Set Cache Policy behavior.
- Select the cache setting you created for the
city
Query String.
- Click the Save button.
Done. Now the content in your application will be cached in the browser and at the origin for the same amount of time it takes for the API to refresh.
Creating advanced cache rules for dynamic content based on Cookies
If your application uses cookie-based authentication, you can use the Advanced Cache Key to ensure that cached content will vary according to each session cookie.
For example, each time a user logs into their account on your edge application, they’re directed to a /profile
page. The contents of the profile page should vary depending on a cookie named session_cookie
and the value it stores upon a successful login.
To ensure a user sees a different page depending on their session cookie:
- Access Azion Console > Edge Application.
- Select the application and ensure Application Accelerator is active.
- Click the Cache Settings tab.
- Click the + Cache Setting button.
- Give your setting an easy-to-remember name.
- Configure Browser Cache Settings and Edge Cache Settings as desired.
- In the Advanced Cache Key section, define your custom Cache by Cookie as follows:
- Select the option Content varies by some Cookies.
- In Cookie names, enter the value
session_cookie
.
- Click the Save button.
The next step is to activate a rule in Rules Engine for the /profile
page as follows:
- Click on the Rules Engine tab.
- Click the + Rule button.
- Give a name to your rule.
- Select the Request Phase.
- In the Criteria section, set the criteria that triggers the behavior every time the URI
/profile
is accessed as follows:
- If
${uri}
starts with/profile
- In the Behaviors section:
- Select the Set Cache Policy behavior.
- Select the cache setting you created for the
session_cookie
.
- Click the Save button.
- Access Real-Time Manager (RTM).
- On the upper-left corner of the page, select Products menu, represented by three horizontal lines.
- Under BUILD, click Edge Application.
- Select the application and ensure Application Accelerator is active.
- Click the Cache Settings tab.
- Click the Add Cache Settings button and give your setting an easy-to-remember name.
- Configure Browser Cache Settings and CDN Cache Settings as desired.
- In the Advanced Cache Key section, define your custom Cache by Cookie as follows:
- Select the option Content varies by some Cookies.
- In Cookie names, enter the value
session_cookie
.
- Click the Save button.
The next step is to activate a rule in Rules Engine for the /profile
page as follows:
- Click on the Rules Engine tab.
- Click the Add Rule button and select the Request Phase.
- In the Criteria section, set the criteria that triggers the behavior every time the URI
/profile
is accessed as follows:- If
${uri}
starts with/profile
- If
- In the Behaviors section:
- Select the Set Cache Policy behavior.
- Select the cache setting you created for the
session_cookie
.
- Click the Save button.
Done. Now the cached object for the profile page will vary based on the user’s session cookie.