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.
Choose your interface once. The prerequisites and the procedure on this page follow that choice.
Prerequisites
- 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.
To create the rule with the Azion CLI, save its definition as rule.json. The file holds the rule’s name, an optional description, whether it is active, its criteria, and its behaviors:
criteria is a list of groups, and each group is a list of conditions. The first condition takes "conditional": "if". In the set_cache_policy behavior, attributes.value holds the ID of your cache setting.
Then create the rule in the Request Phase, with your application ID in place of <application-id>:
The command prints the ID of the new rule:
The --phase flag sets the phase of the rule. The file holds the same body that the API accepts.
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.