# How to configure Advanced Cache Key for Applications

Azion **Application Accelerator** enables access to the [Advanced Cache Key](/en/documentation/products/build/applications/cache-settings/#advanced-cache-key) feature, which allows you to create cache rules based on URL Query Strings and Cookies. You can apply these rules to a dynamic application using [Rules Engine](/en/documentation/products/build/applications/rules-engine/).

To activate **Advanced Cache Key** for an application:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Applications**.
2. Select the application you want to configure or [create a new one](/en/documentation/products/guides/build/build-an-application/).
3. On the **Main settings** tab, in the **Modules** section, enable the **Application Accelerator** switch.
4. Click the **Save** button.

:::tip
If you want to configure cache settings for static content, see the guide on [How to configure cache policies for Applications](/en/documentation/products/guides/cache-settings/).
:::

---

## Creating advanced cache rules for dynamic content based on Query Strings

To illustrate the use of **Advanced Cache Key** based on Query Strings, assume your application has the following URL: `domain.com/page?city=city_name`.

The `/page` URI has an API, called by the Query String `?city=city_name` that lists the content depending on the user's city. The content of the page is automatically updated every five minutes.

In order to match the cache TTL with the update time of the content called by the `city` field:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Applications**.
2. Select the application and ensure **Application Accelerator** is active.
3. Click on the **Cache Settings** tab.
4. Click on the **+ Cache Setting** button.
5. Give your setting an easy-to-remember name.
6. Both in the **Browser Cache Settings** and **Cache Settings** sections:
    - Check the option **Override Cache Settings**.
    - Set the **Maximum TTL (seconds)** to `300` (5 minutes).
7. In the **Advanced Cache Key** section, define your custom **Cache by Query String** as follows:
    - Select the option **Content varies by some Query String fields (Allowlist)**.
    - In **Query String fields**, enter the value `city`.
    - This field is case-sensitive and treats uppercase and lowercase letters differently when storing objects in the cache.
8. Click the **Save** button.

Now, there's a cache policy object with the Query String for `city` that can be activated in **Rules Engine** as follows:

1. Click on the **Rules Engine** tab.
2. Click the **+ Rule** button.
3. Give a name to your rule.
4. Select the **Request Phase**.
5. In the **Criteria** section, set the criteria that triggers the behavior every time the URI `/page` is accessed as follows:
    - If `${uri}` *starts with* `/page`
6. In the **Behaviors** section:
    - Select the **Set Cache Policy** behavior.
    - Select the cache setting you created for the `city` Query String.
7. Click the **Save** button.

Done. Now the content in your application will be cached in the browser and at the origin for the same amount of time it takes for the API to refresh.

---

## Creating advanced cache rules for dynamic content based on Cookies

If your application uses cookie-based authentication, you can use the **Advanced Cache Key** to ensure that cached content will vary according to each session cookie.

For example, each time a user logs into their account on your application, they're directed to a `/profile` page. The contents of the profile page should vary depending on a cookie named `session_cookie` and the value it stores upon a successful login.

To ensure a user sees a different page depending on their session cookie:

1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Applications**.
2. Select the application and ensure **Application Accelerator** is active.
3. Click the **Cache Settings** tab.
4. Click the **+ Cache Setting** button.
5. Give your setting an easy-to-remember name.
6. Configure **Browser Cache Settings** and **Cache Settings** as desired.
7. In the **Advanced Cache Key** section, define your custom **Cache by Cookie** as follows:
    - Select the option **Content varies by some Cookies**.
    - In **Cookie names**, enter the value `session_cookie`.
    - This field is case-sensitive and treats uppercase and lowercase letters differently when storing objects in the cache.
8. Click the **Save** button.

The next step is to activate a rule in **Rules Engine** for the `/profile` page as follows:

1. Click on the **Rules Engine** tab.
2. Click the **+ Rule** button.
3. Give a name to your rule.
4. Select the **Request Phase**.
5. In the **Criteria** section, set the criteria that triggers the behavior every time the URI `/profile` is accessed as follows:
- If `${uri}` starts with `/profile`
6. In the **Behaviors** section:
    - Select the **Set Cache Policy** behavior.
    - Select the cache setting you created for the `session_cookie`.
7. Click the **Save** button.

Done. Now the cached object for the profile page will vary based on the user's session cookie.