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:

  1. Access Azion Console > Edge Application.
  2. Select the application you want to configure or create a new one.
  3. On the Main settings tab, in the Modules section, enable the Application Accelerator switch.
  4. 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:

  1. Access Azion Console > Edge Application.
  2. Select the application and ensure Application Accelerator is active.
  3. Click on the Cache Settings tab.
  4. Click on the + Cache Setting button.
  5. Give your setting an easy-to-remember name.
  6. 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).
  7. 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.
  8. 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:

  1. Click on the Rules Engine tab.
  2. Click the + Rule button.
  3. Give a name to your rule.
  4. Select the Request Phase.
  5. 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
  6. In the Behaviors section:
    • Select the Set Cache Policy behavior.
    • Select the cache setting you created for the city Query String.
  7. 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:

  1. Access Azion Console > Edge Application.
  2. Select the application and ensure Application Accelerator is active.
  3. Click the Cache Settings tab.
  4. Click the + Cache Setting button.
  5. Give your setting an easy-to-remember name.
  6. Configure Browser Cache Settings and Edge Cache Settings as desired.
  7. 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.
  8. Click the Save button.

The next step is to activate a rule in Rules Engine for the /profile page as follows:

  1. Click on the Rules Engine tab.
  2. Click the + Rule button.
  3. Give a name to your rule.
  4. Select the Request Phase.
  5. 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
  1. In the Behaviors section:
    • Select the Set Cache Policy behavior.
    • Select the cache setting you created for the session_cookie.
  2. Click the Save button.

Done. Now the cached object for the profile page will vary based on the user’s session cookie.


Contributors