Cache POST and OPTIONS responses
Store the response to a POST or OPTIONS request on an application, then apply the cache setting with a Rules Engine rule.
Application Accelerator unlocks the caching of POST and OPTIONS responses, beyond the GET and HEAD requests an application caches natively. You select the methods in a cache setting from Azion Console, then apply that cache setting with Rules Engine.
A cached POST object does not share a cache key with the GET response for the same path. Azion prefixes the method to the key of any request other than GET or HEAD. For a cached POST or OPTIONS object, the key also appends @@ and the MD5 hash of the request body. An OPTIONS request to https://static.yourdomain.com/page is stored under the key optionshttpsstatic.yourdomain.com/page. A POST to a dynamic path is stored under httpsdynamic.yourdomain.com/path@@md5_of_post_arguments.
A POST body that varies per request therefore produces one cached object per request. For what a variation costs, refer to Cache variation.
Prerequisites
- An application. To create one, refer to Applications quickstart.
- Access to Azion Console. Refer to Access Azion Console.
- Application Accelerator can generate usage-related costs. For the rates, refer to Pricing.
Turn on Application Accelerator
The module is off by default, and a cache setting stores a POST or OPTIONS response only while the module is on. To turn it on:
Access Azion Console > Applications > your application.
On the Main Settings tab, in the Modules section, turn on Application Accelerator.
The application runs with Application Accelerator, and its cache settings can select the POST and OPTIONS methods.
Cache the responses to POST requests
An application serves a search API at /api/search. The endpoint answers a POST request whose body carries the search terms, and the results change every 30 seconds. To store one object per body, and to expire it at the same interval:
Access Azion Console > Applications > your application, then go to the Cache Settings tab.
In Name, enter a name that identifies the setting. For example: search-post.
Under Cache, select Override cache behavior and set Max Age to 30.
Under Application Accelerator, open Cache vary by Method and select the POST checkbox.
The cache setting appears in the Cache Settings tab. It stores the response to a POST request once a rule applies it.
Cache vary by Method holds two checkboxes, POST and OPTIONS. To cache OPTIONS responses, select OPTIONS in the same control; one cache setting can carry both methods. The Azion API sets the same methods with the cache_vary_by_method field of a cache setting, documented in Application Accelerator settings.
A cache setting takes effect only when a rule applies it. To apply this one to the /api/search URI:
Enter a name for the rule. For example: search-post rule.
In the Criteria section, select the ${uri} variable.
Enter /api/search as the argument.
Requests whose URI starts with /api/search carry the cache setting. Azion stores one object per request body and holds each object for 30 seconds. A new rule takes a few minutes to propagate.
A cached POST or OPTIONS object expires with a cache key purge that lists each variation, or with a wildcard purge ending in @@*. For the purge types, refer to Real-Time Purge.