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 has Cache on, as every Application does. The cache setting belongs to the Application. It holds the time to live (TTL), how long Azion keeps a copy. It also holds what Azion does with that copy.
The rule, also on the Application, matches requests by path and applies the setting through the Set Cache Policy behavior. A cache setting acts only once a rule applies that cache setting. A matching request is answered from the stored copy when one exists. With the Pragma: azion-debug-cache header, its response reports HIT in x-cache.
Prerequisites
Console
- 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 under a path prefix such as
/static/, 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, and what Azion does with that copy. This one keeps each copy for 300 seconds.
Console
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, Browser Cache, and Cache.
Apply the setting with a rule
A cache setting acts only once a rule applies that cache setting. This rule applies static-assets to every request whose path matches a prefix you choose.
Console
To create the rule in Azion Console:
Access Azion Console > Applications, then select the Application that serves your content.
In Name, enter cache-static-assets.
Under Criteria, select ${uri} and starts with. As the argument, enter /static/, or the path prefix of your object.
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 starts with /static/.
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. Each server keeps its own copy, so a request that another server answers can report MISS once more. Run the command again.
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.