# Cache Settings

import DocButton from '~/components/webkit/DocButton.vue';

With **Cache Settings** for **Applications**, you can edit cache configurations for static and dynamic content.

## Implementation

| Scope | Resource |
| --- | --- |
| Applications first steps | [First steps](/en/documentation/products/build/applications/first-steps/) |
| Cache module | [Cache](/en/documentation/products/build/applications/cache/)  |
| Tiered Cache module | [Tiered Cache](/en/documentation/products/build/applications/cache/tiered-cache/) |
| Creating a cache setting | [How to configure cache policies for Applications](/en/documentation/products/guides/cache-settings/) |
| Configuring Advanced Cache Key | [How to configure Advanced Cache Key for Applications](/en/documentation/products/guides/advanced-cache-key/) |

---

## Browser Cache Settings

**Browser Cache Settings** configures the amount of time that content is cached in the user's browser. You can select from the following options:

- **Honor Origin Cache Headers**: honors the cache definitions sent by your origin servers through HTTP headers (`Cache-Control` and `Expires`), sending the same headers to the web browser.
- **Override Cache Settings**: overrides the cache of your origin server and allows you to set the cache time-to-live (TTL) manually.

---

## CDN Cache Settings

**CDN Cache Settings** configures how Azion caches the content at the edge. You can select from the following options:

- **Honor Origin Cache Headers**: maintains the cache definitions sent by your origin servers through HTTP headers (*Cache-Control and Expires*), sending the same headers to the web browser.
- **Override Cache Settings**: overrides the cache setting of your origin server with the desired TTL. To set the TTL of CDN cache to values under 60 seconds, you must enable the [Application Accelerator](/en/documentation/products/build/applications/application-accelerator/) module.

---

## Large File Optimization

**Large File Optimization** works with a default fragment size of *1024 kB*. If you want to modify the fragmentation range, [contact the Sales team](https://www.azion.com/en/contact/).

<DocButton href="/en/documentation/products/build/applications/cache/#large-file-optimization" label="go to Large File Optimization documentation" size="medium" />

:::note
When activating this feature, each fragment of the file within the defined the range will carry a different cache key.
:::

Large File Optimization can be applied to both the cache layer at the edge and the tiered cache layer, provided that **Tiered Cache** is an active module.

<DocButton href="/en/documentation/products/build/applications/cache/tiered-cache/" label="go to Tiered Cache documentation" size="medium" />

---

## Advanced Cache Key 

You can use **Advanced Cache Key** to customize cache rules based on the following metadata:

- Cookies
- Query strings

> For both cases, this field is case-sensitive, meaning it treats uppercase and lowercase letters differently when caching objects.

### Cache by Query String

At Azion, you define how you want the content to be cached according to **Query String** variations in your URLs:

- **Content does not vary by Query String (Improves Caching)**: defines that the cache key must ignore the query string. That is, two URLs that are different just by the variation of the query string will be considered as the same cached object. 
  - For example, `http://yourdomain.com/path?queryA` and `http://yourdomain.com/path?queryB` will deliver the same cache content to your users.

- **Content varies by some Query String fields (Whitelist)**: you can list which query string fields should be considered to differentiate between objects in the Azion cache. All other fields will be ignored. 
  - For example, if you list the `city` field, the URLs `http://yourdomain.com/path?city=A&name=X` and `http://yourdomain.com/path?city=A&name=Y` will be considered as a single object in cache, while URLs `http://yourdomain.com/path?city=A&name=X` and `http://yourdomain.com/path?city=B&name=X` will be considered as different objects.

- **Content varies by Query String, except for some fields (Blocklist)**: you can list which fields in the query string should be ignored when differentiating cached objects. All other fields will be considered. 
  - For example, if you list the `random` field, the URLs `http://yourdomain.com/path?city=A&random=123` and `http://yourdomain.com/path?city=B&random=123` will be considered different object in cache, while `http://yourdomain.com/path?city=A&random=123` and `http://yourdomain.com/path?city=A&random=456` will be considered as the same object in cache.

- **Content varies by all Query String fields**: defines that the cache key must consider all fields of the query string. That is, two URLs distinct by the variation of the query string will be considered as two distinct objects in the cache. 
  - For example, `http://yourdomain.com/path?queryA` and `http://yourdomain.com/path?queryB` will be stored as separate objects in the Azion cache.

In order to increase caching efficiency, you can enable the **Query String Sort** option. If activated, it orders all the fields of the query string, making the position of the fields irrelevant in the definition of the cache key. If the position of the fields is relevant to differentiate your content, you should disable this option.

### Cache by Cookie

You can also distinguish objects in the Azion cache by name/value of cookies.

- **Content does not vary by Cookies (Improves Caching)**: differentiates objects in Azion's cache through URL; doesn't take cookies into account.

- **Content varies by some Cookies (Allowed Rules)**: you can list the name of the cookies that your application uses to differentiate cached objects. All other cookies will be ignored, allowing you to segment your content by user profiles and other settings. This is the most recommended option if you use cookies to manage user sessions.

- **Content varies by Cookies, with the exception of a few (Blocklist)**: you can list the name of the cookies you want to ignore in the cache key setting, considering all cookies except those listed.

- **Content varies by all Cookies**: in addition to the URL, it considers all cookies to differentiate objects in Azion's cache.

:::tip
Use this feature to segment your content by user profile, browsing session, access region, or according to your content targeting needs.
:::

---

## Caching HTTP Methods 

You can enable the **Enable caching for POST** switch, allowing Azion to cache `POST` requests; the **Enable caching for OPTIONS** key allows Azion to cache `OPTIONS` requests. These two cache options require the request body to be part of the cache key.

---

## Stale Cache 

With the **Cache** module, you can enable **Stale Cache** to serve stale content when there's a problem with your origin servers.

<DocButton href="/en/documentation/products/build/applications/cache/#stale-cache" label="go to stale cache documentation" size="medium" />

---

## Adaptive Delivery

With the **Cache** module, you can select a device group for **Adaptive Delivery**.

When choosing the option **Content varies by some Device Groups (Whitelist)**, you're allowing Azion to keep device-based variations of its objects in cache.

<DocButton href="/en/documentation/products/build/applications/device-groups/" label="go to Device Groups documentation" size="medium" />