Configure Advanced Cache Key for an application
Vary a cached object by a query string argument or by a cookie, then apply the cache setting to an application with a Rules Engine rule.
Application Accelerator unlocks Advanced Cache Key, which varies a cached object by query string argument or by cookie. You configure it in a cache setting from Azion Console, then apply that cache setting with Rules Engine.
For content that does not vary between requests, refer to Configure cache policies. For what a variation changes in the cache key, refer to Cache variation.
Prerequisites
- An application. To create one, refer to Applications quickstart.
- Access to Azion Console. Refer to Access Azion Console.
- Application Accelerator can generate usage-related costs. For the rates, refer to Pricing.
Turn on Application Accelerator
The module is off by default, and a cache setting varies the cached object only while the module is on. To turn it on:
Access Azion Console > Applications > your application.
On the Main Settings tab, in the Modules section, turn on Application Accelerator.
The application runs with Application Accelerator, and its cache settings can vary the cached object by query string or cookie.
Vary the cache by a query string argument
An application serves the URL domain.com/page?city=city_name. The /page URI calls an API that lists content for the city in the city argument. The API refreshes that content every five minutes. To store one object per city, and to expire it at the same interval:
Access Azion Console > Applications > your application, then go to the Cache Settings tab.
In Name, enter a name that identifies the setting. For example: city-listing.
Under Browser Cache, select Override cache settings and set the maximum age to 300.
Under Cache, select Override cache behavior and set Max Age to 300.
Under Application Accelerator, open Cache vary by Query String and set Behavior to Allowlist.
Add city to the list of query string arguments.
The cache setting appears in the Cache Settings tab, and it varies the cached object by the city argument.
A cache setting takes effect only when a rule applies it. To apply this one to the /page URI:
Enter a name for the rule. For example: city-listing rule.
In the Criteria section, select the ${uri} variable.
Enter /page as the argument.
Requests whose URI starts with /page carry the cache setting. The browser and Azion hold each city object for 300 seconds. A new rule takes a few minutes to propagate.
Vary the cache by a cookie
An application authenticates users with a cookie, and the /profile page it serves after a login must differ per session. The cookie session_cookie carries the value that identifies the session. To store one object per session:
Access Azion Console > Applications > your application, then go to the Cache Settings tab.
In Name, enter a name that identifies the setting. For example: profile-by-session.
In the Browser Cache and Cache sections, set the behavior and the age the profile page needs.
Under Application Accelerator, open Cache vary by Cookies and set Behavior to Allowlist.
Add session_cookie to the list of cookie names.
The cache setting appears in the Cache Settings tab, and it varies the cached object by the value of session_cookie. Cookie names are case sensitive, like every value that composes a cache key.
To apply this cache setting to the /profile URI:
Enter a name for the rule. For example: profile rule.
In the Criteria section, select the ${uri} variable.
Enter /profile as the argument.
Requests whose URI starts with /profile carry the cache setting. Each session receives the object cached for its own session_cookie value. A new rule takes a few minutes to propagate.