Create an application rule
Add a rule to an application from Azion Console, the Azion CLI, or the API, and apply a cache setting to every path that starts with /static/.
You can create a rule in Rules Engine for Applications from Azion Console, the Azion CLI, or the API. A rule runs its behaviors on every request that matches its criteria. The application changes what it does, and your code stays as it is. Rules are also how the application uses its cache settings, function instances, and connectors. The rule on this page applies a cache setting to the paths that start with /static/.
To rewrite a request path or remove the Server header from responses, refer to Create request and response rules. A firewall has rules of its own. For those, refer to Create a firewall rule.
Prerequisites
Console
- An application that serves your traffic through a workload. To create one, refer to Applications quickstart.
- A cache setting on that application. To create one, refer to Create a cache setting.
- Access to Azion Console. To sign in, refer to Access Azion Console.
Apply a cache setting to one path
The rule in this section runs in the Request Phase. It matches the requests whose ${uri} starts with /static/. Its Set Cache Policy behavior applies your cache setting to them. Requests to other paths keep the cache behavior they had. The criterion also matches longer paths, such as /static/css/site.css.
A rule’s phase is fixed when you create it. To run a behavior in the Response Phase instead, create a new rule in that phase.
The ${uri} variable needs no Product on the application. Set Cache Policy relies on Cache, which every new application runs. Other variables and behaviors need Application Accelerator, Image Processor, or Functions enabled on the application. In Azion Console, each of those options carries a note such as - Required Application Accelerator. To enable a Product, refer to Enable Products on an application.
Console
To create the rule in Azion Console:
Access Azion Console > Applications, then select your application.
In the General section, enter a Name, such as apply-static-assets-cache.
In Description, enter a note about what the rule does. The note takes up to 1,000 characters.
In the Phase section, select Request Phase.
In the Criteria section, select ${uri} as the variable.
Select starts_with as the operator.
Enter /static/ as the argument.
In the Behaviors section, select Set Cache Policy.
In the second dropdown of the behavior, select your cache setting.
Under Status, make sure that Active is turned on.
The rule appears in the Rules Engine tab, under the Request heading. To run a second behavior in the same rule, select + Add Behavior before you save it.
A new rule can take a few minutes to propagate. To read the cache status of a response under /static/, refer to Check the cache status of a response.