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.

If you want to configure cache settings for static content, see the guide on How to configure cache policies for Edge Application.

To activate Advanced Cache Key for an edge application:

  1. Access Azion Console.
  2. On the upper-left corner of the page, select Products menu, represented by three horizontal lines.
  3. Under BUILD, click Edge Application.
  4. Select the application you want to configure or create a new one.
  5. On the Main settings tab, under the Modules section, enable the Application Accelerator switch.
  6. Click the Save button.

Creating advanced cache rules for dynamic content based on Query Strings

Section titled 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.
  2. On the upper-left corner of the page, select Products menu, represented by three horizontal lines.
  3. Under BUILD, click Edge Application.
  4. Select the application and ensure Application Accelerator is active.
  5. Click on the Cache Settings tab.
  6. Click on the Add Cache Settings button and give your setting an easy-to-remember name.
  7. 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).
  8. 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.
  9. 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 Add Rule button and select the Request Phase.

  3. 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

  4. In the Behaviors section:

    • Select the Set Cache Policy behavior.
    • Select the cache setting you created for the city Query String.
  5. 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

Section titled 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.
  2. On the upper-left corner of the page, select Products menu, represented by three horizontal lines.
  3. Under BUILD, click Edge Application.
  4. Select the application and ensure Application Accelerator is active.
  5. Click the Cache Settings tab.
  6. Click the Add Cache Settings button and give your setting an easy-to-remember name.
  7. Configure Browser Cache Settings and CDN Cache Settings as desired.
  8. 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.
  9. 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 Add Rule button and select the Request Phase.

  3. 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

  4. In the Behaviors section:

    • Select the Set Cache Policy behavior.
    • Select the cache setting you created for the session_cookie.
  5. Click the Save button.

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


Contributors