Cache quickstart
Create a cache setting in Azion Console, the Azion CLI, or the API, apply it to one path with a Rules Engine rule, and read the cache status of a response.
This guide instructs you through caching a path of your application for the first time. By the end you will have:
- A cache setting that keeps a copy of each response for 300 seconds.
- A Rules Engine rule that applies the setting to one path prefix.
- The cache status of a response, read from its
x-cacheheader.
The result rests on four objects, in this order. The application carries the Cache module, which is on for every application. The cache setting belongs to the application and holds the TTL, the time Azion keeps a copy. The rule, also on the application, matches requests by path and applies the setting through the Set Cache Policy behavior. A matching request is answered from the stored copy when one exists, and its response carries x-cache with HIT. Until a rule names it, a cache setting does nothing.
Select the interface you will use. The prerequisites and every stage below follow that choice.
Prerequisites
- An application that already serves content on a domain. To create one, refer to Applications quickstart.
- The URL of a static object the application serves, such as an image, to check at the end.
curlon your machine, for the cache status check at the end.
- Access to Azion Console. To sign in, refer to Access Azion Console.
Create a cache setting
A cache setting holds how long Azion keeps a copy of a response. This one keeps each copy for 300 seconds.
To create the cache setting in Azion Console:
Access Azion Console > Applications, then select the application that serves your content.
In Name, enter static-assets.
Under Cache, keep Override cache behavior selected. With this option, Max Age replaces the TTL the origin sends.
In Max Age, replace 60 with 300.
The new setting appears in the Cache Settings list, which shows its Name, ID, Browser Cache, and Cache.
Apply the setting with a rule
A cache setting does nothing until a rule names it. This rule applies static-assets to every request whose path matches a prefix you choose.
To create the rule in Azion Console:
Enter a name such as cache-static-assets.
Under Criteria, select ${uri} and an operator. As the argument, enter the path prefix to cache, such as /static/.
Under Behaviors, select Set Cache Policy, then select static-assets.
The rule appears in the list and applies static-assets to every request whose path matches its criteria.
Check the cache status
The request header Pragma: azion-debug-cache makes the response carry two debug headers. x-cache holds the cache status, the IP of the server that answered, and the protocol. x-cache-key holds the key that indexes the copy.
Request an object under the path the rule matches, with your own host and path:
The response carries the two debug headers. Under HTTP/2, the header names arrive in lowercase:
MISS means the object was not in the cache: Azion fetched it from the origin and may store the response.
A response answered from the stored copy carries HIT. x-cache also names the server that answered.
Your application now keeps a copy of each matching response for 300 seconds. x-cache tells you when a response came from that copy. A response can also carry another status, such as REVALIDATED. For every status value, refer to Cache keys.