Application Accelerator quickstart
Turn on Application Accelerator, cache a listing that varies by a query string argument, and read the variation in the cache key.
This guide instructs you through your first cache setting that varies the cache key. The example is a listing page whose response changes with one query string argument.
- Turn on Application Accelerator on an application.
- Create a cache setting that holds the listing for 30 seconds and varies by the
categoryargument. - Add a Rules Engine rule that applies the cache setting to requests for
/products. - Request the listing twice, with two values of
category, and read the cache key of each response.
Three objects produce that result, and each one depends on the one before it:
- The Application Accelerator switch belongs to the application. It unlocks the fields that vary the cache key, and it removes the 60-second floor on the cache TTL.
- The cache setting holds the cache behavior, the Max Age, and the variation. It names what the cache does, not which requests it does it to.
- The Rules Engine rule applies the cache setting with the Set Cache Policy behavior. Its criteria decide which requests the cache setting covers.
Creating a cache setting changes no traffic. A cache setting that no rule applies never reaches a request.
azion.config.js and Azion Lib carry the same settings. For the field each interface sets, refer to Application Accelerator settings.
Select the interface you will use. The prerequisites and every stage below follow that choice.
Prerequisites
- An Azion account. To create one, refer to How to create an account on Azion.
- The Edit Applications permission on the account. It grants permission to edit, create, and remove applications, and it also requires the permission View Applications. Refer to Teams permissions.
- An application that serves a path whose response changes with a query string argument. This guide uses the
/productspath and thecategoryargument. To create an application, refer to Applications quickstart.
- Access to Azion Console. To sign in, refer to Access Azion Console.
Turn on Application Accelerator
The module is off by default, and it belongs to one application at a time.
To turn on the module in Azion Console:
Access Azion Console > Applications.
In the Modules section, turn on Application Accelerator.
The application now accepts the cache fields the rest of this guide uses.
Create a cache setting that varies by query string
A cache setting is where the cache behavior and the variation live. The Max Age of 30 seconds below is the point of the exercise: without Application Accelerator, the shortest cache TTL an application accepts is 60 seconds.
To create the cache setting in Azion Console:
Enter a value in Name. For example: product-listing.
Under Cache, select Override cache behavior and set Max Age to 30.
Under Application Accelerator, open Cache vary by Query String and set Behavior to Allowlist.
Add category to the field list under Behavior.
Turn on Sort.
The cache setting appears in the Cache Settings tab. It holds an object for 30 seconds and gives each value of category its own cached object.
Apply the cache setting with a rule
A cache setting reaches a request only when a rule applies it.
To apply the cache setting to the listing path in Azion Console:
Enter a name for the rule. For example: Cache the product listing.
Select Request Phase.
In the Criteria section, select the ${uri} variable.
Select starts with as the comparison operator.
Enter /products as the argument.
In the Behaviors section, select Set Cache Policy.
The rule applies the cache setting to every request whose URI starts with /products.
A new rule takes a few minutes to propagate. Wait before you request the path.
Read the cache key
Azion returns the cache key of an object when the request carries the Azion debug header Pragma: azion-debug-cache. Reading that key for two values of category shows the variation the cache setting created.
Your application answers on a domain in the format xxxxxxxxx.map.azionedge.net. To set the domain for your application, refer to Add a custom domain to a workload.
Replace <your-azion-domain> with that domain, and request the listing with one value:
The response carries two Azion debug headers. This excerpt is from an application served at www.example.com, and HTTP/2 sends header names in lowercase:
x-cache carries the cache status, the address of the data center that answered, and the protocol of the request. x-cache-key carries the cache key, which concatenates the scheme, the host, the path, and the query string arguments the allowlist named.
Request the same path with a different value:
The argument changed, so the key changed with it:
Two keys are two cached objects, which is what the allowlist asked for. For the full format of a cache key, refer to Cache key format.
Your application now caches the /products listing for 30 seconds and keeps one object per value of category.