---
name: azion-configure-advanced-cache-key-for-an-application
description: >-
  Vary a cached object by a query string argument or by a cookie, then apply the cache setting to an application with a Rules Engine rule.
---

# Configure Advanced Cache Key for an application

[Application Accelerator](/en/documentation/platform/applications/#application-accelerator) unlocks [Advanced Cache Key](/en/documentation/platform/applications/cache/cache-settings/#application-accelerator), which varies a cached object by query string argument or by cookie. You configure it in a cache setting from Azion Console, then apply that cache setting with [Rules Engine](/en/documentation/platform/applications/rules-engine/).

For content that does not vary between requests, refer to [Configure cache policies](/en/documentation/guides/application-performance/cache-and-purge/cache-settings/). For what a variation changes in the cache key, 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 varies the cached object 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 vary the cached object by query string or cookie.

---

## Vary the cache by a query string argument

An application serves the URL `domain.com/page?city=city_name`. The `/page` URI calls an API that lists content for the city in the `city` argument. The API refreshes that content every five minutes. To store one object per city, 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: `city-listing`.

4. **Set the browser cache**

   Under **Browser Cache**, select *Override cache settings* and set the maximum age to `300`.

5. **Set Max Age**

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

6. **Allowlist the argument**

   Under **Application Accelerator**, open **Cache vary by Query String** and set **Behavior** to *Allowlist*.

7. **Enter the argument**

   Add `city` to the list of query string arguments.

8. **Select Save**

The cache setting appears in the **Cache Settings** tab, and it varies the cached object by the `city` argument.

> **Note**
>
> Cache keys are case sensitive. Azion stores `?city=Lisbon` and `?city=lisbon` as two objects.

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

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

2. **Select + Rule**

3. **Name the rule**

   Enter a name for the rule. For example: `city-listing 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 `/page` 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 `/page` carry the cache setting. The browser and Azion hold each city object for 300 seconds. A new rule takes a few minutes to propagate.

---

## Vary the cache by a cookie

An application authenticates users with a cookie, and the `/profile` page it serves after a login must differ per session. The cookie `session_cookie` carries the value that identifies the session. To store one object per session:

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: `profile-by-session`.

4. **Set the cache behavior**

   In the **Browser Cache** and **Cache** sections, set the behavior and the age the profile page needs.

5. **Allowlist the cookie**

   Under **Application Accelerator**, open **Cache vary by Cookies** and set **Behavior** to *Allowlist*.

6. **Enter the cookie name**

   Add `session_cookie` to the list of cookie names.

7. **Select Save**

The cache setting appears in the **Cache Settings** tab, and it varies the cached object by the value of `session_cookie`. Cookie names are case sensitive, like every value that composes a cache key.

To apply this cache setting to the `/profile` URI:

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

2. **Select + Rule**

3. **Name the rule**

   Enter a name for the rule. For example: `profile 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 `/profile` 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 `/profile` carry the cache setting. Each session receives the object cached for its own `session_cookie` value. A new rule takes a few minutes to propagate.

---

## Next steps

- [Cache variation](/en/documentation/platform/applications/application-accelerator/cache-variation.md): What a variation changes in the cache key, and what it 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 an object that varies, which a URL purge does not always reach.
- [Verify cache indicators with ModHeader](/en/documentation/guides/application-performance/cache-and-purge/check-page-cache-time.md): Read the cache headers a request returns and confirm the variation you configured.
- [Optimize images for websites and mobile apps](/en/documentation/use-cases/improve-performance-and-reliability/optimize-images-for-websites-and-mobile-apps.md): A cache setting that varies by the ims argument, so each image size is cached once.
