---
name: azion-cache-post-and-options-responses
description: >-
  Store the response to a POST or OPTIONS request on an application, then apply the cache setting with a Rules Engine rule.
---

# Cache POST and OPTIONS responses

[Application Accelerator](/en/documentation/platform/applications/#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](/en/documentation/platform/applications/rules-engine/).

A cached `POST` object does not share a [cache key](/en/documentation/platform/applications/cache/cache-keys/) 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](/en/documentation/platform/applications/application-accelerator/cache-variation/).

---

## Prerequisites

- An application. To create one, refer to [Applications quickstart](/en/documentation/platform/applications/quickstart/).
- Access to Azion Console. Refer to [Access Azion Console](/en/documentation/guides/platform/account-and-billing/how-to-access-azion-console/).
- Application Accelerator can generate usage-related costs. For the rates, refer to [Pricing](/en/documentation/fundamentals/pricing/#application-accelerator).

---

## 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:

1. **Open the application**

   Access [Azion Console](https://console.azion.com/) > **Applications** > **your application**.

2. **Turn on the module**

   On the **Main Settings** tab, in the **Modules** section, turn on **Application Accelerator**.

3. **Select Save**

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:

1. **Open the Cache Settings tab**

   Access [Azion Console](https://console.azion.com/) > **Applications** > **your application**, then go to the **Cache Settings** tab.

2. **Select + Cache**

3. **Name the cache setting**

   In **Name**, enter a name that identifies the setting. For example: `search-post`.

4. **Set Max Age**

   Under **Cache**, select *Override cache behavior* and set **Max Age** to `30`.

5. **Select the POST method**

   Under **Application Accelerator**, open **Cache vary by Method** and select the **POST** checkbox.

6. **Select Save**

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](/en/documentation/platform/applications/application-accelerator/settings/).

A cache setting takes effect only when a rule applies it. To apply this one to the `/api/search` URI:

1. **Go to the Rules Engine tab**

2. **Select + Rule**

3. **Name the rule**

   Enter a name for the rule. For example: `search-post rule`.

4. **Select Request Phase**

5. **Select the variable in the Criteria section**

   In the **Criteria** section, select the `${uri}` variable.

6. **Select starts with as the comparison operator**

7. **Enter the argument**

   Enter `/api/search` as the argument.

8. **In the Behaviors section, select Set Cache Policy**

9. **Select the cache setting you created**

10. **Select Save**

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.

> **Note**
>
> Before a cache setting selects **POST**, a `POST` request logs no cache status: the `X-Cache` header carries `-`, because the content is restricted from caching. To read the header on a request, refer to [Verify cache indicators with ModHeader](/en/documentation/guides/application-performance/cache-and-purge/check-page-cache-time/).

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](/en/documentation/platform/applications/cache/real-time-purge/#purge-content-that-varies).

---

## Next steps

- [Cache variation](/en/documentation/platform/applications/application-accelerator/cache-variation.md): What the request body adds to the cache key, and what a variation costs you in stored objects.
- [Application Accelerator settings](/en/documentation/platform/applications/application-accelerator/settings.md): Every field the module adds to a cache setting, with its values and defaults.
- [Real-Time Purge](/en/documentation/platform/applications/cache/real-time-purge.md): Expire a cached POST object with a cache key purge or a wildcard purge.
- [Configure Advanced Cache Key](/en/documentation/guides/application-performance/cache-and-purge/advanced-cache-key.md): Vary a cached object by a query string argument or by a cookie.
