# Configure OData output cache

## Overview

Sitefinity CMS output cache implementation guarantees that your sites perform optimally and can handle peaks in user load. Using distributed output cache enhances this effect further, because items, stored in output cache, remain available even during website restarts or IIS AppPool recycles.

Output cache is supported for OData services. The cache is supported only for unauthenticated, frontend requests. OData output cache works the same way as the standard output cache – it can be enabled and disabled, and it is configurable via cache profiles.

## Enable and disable OData output cache

You can enable and disable OData output cache for the whole Sitefinity CMS instance.\
Perform the following:

1. In Sitefinity CMS backend, navigate to *Administration » Settings » Advanced*.
2. In the tree view on the left, expand *System » Output Cache Settings*.
3. Select or deselect the *Enable output cache* checkbox.
4. Save your changes.

## Create and edit OData output cache profiles

Perform the following:

1. In Sitefinity CMS backend, navigate to *Administration » Settings » Advanced*.
2. In the tree view on the left, expand *System » Output Cache Settings » Web Services Cache Profiles*.
3. To create a new profile, click *Create new* and fill out the following and save your changes:

<table>
<tbody>
<tr>
<td>

**Setting**

</td>
<td>

**Description**

</td>
</tr>
<tr>
<td>

*Name*

</td>
<td>

Defines the programmatic name of the profile.<br>
This is the name used to access the profile.

</td>
</tr>
<tr>
<td>

*Location*

</td>
<td>

<p>Specifies the location of the cached HTTP response content.<br>
You can choose one of the following values:</p>

<ul>
<li><em>None</em><br>
No cache profile is applied, the client sends new requests and the server generates content for the response on every request</li>
<li><em>Server</em><br>
Cache is applied only on the server, the client still sends new requests.</li>
<li><em>Client</em><br>
Cache is applied only on the client, the server generates content every time there is a request to it.</li>
<li><em>ServerAndClient</em><br>
Cache is applied both on client and on the original (hosting) server, that is, not just any proxy server</li>
<li><em>Any</em><br>
Cache is applied on the browser client (where the request originated), on a proxy server and any other server participating in the request (where the request was processed)
</li>
</ul>

</td>
</tr>
<tr>
<td>

*Duration*

</td>
<td>

Specifies the maximum time in seconds that the fetched response is allowed to be reused from the time of the request.

</td>
</tr>
<tr>
<td>

*Sliding expiration*

</td>
<td>

Indicates whether the expiration time is reset on every request.

</td>
</tr>
<tr>
<td>

*Client Max Age*

</td>
<td>

Specifies the maximum time in seconds that the fetched response is allowed to be reused from the time of the request.

Corresponds to the `max-age` directive of the `cache-control` header. If this value is not specified, the system uses the client caching and the `Duration` property sets the client cache max age.

</td>
</tr>
<tr>
<td>

*Proxy or Max Age*

</td>
<td>

This setting corresponds to the `s-maxage` cache-control directive and it explicitly applies to proxy servers.

The proxy max age property overrides the `max-age` directive and expires the header field when present.

</td>
</tr>
</tbody>
</table>

## Configure OData output cache per route

To configure specific route:

1. Navigate to *Administration » Settings » Advanced*.
2. In three on the left, expand *WebServices » Routes » \<YourRouteName> » Services » \<YourServiceName>*.
3. In *Output cache profile* field, enter the name of the profile that you want to apply to this specific route.

   > info  **NOTE**: If the you leave the field empty, the system uses the default output cache profile.
4. Save your changes.

## Cache invalidation

Output cache increases your website performance. In some cases, however, you might want to have a mechanism for on-demand invalidation of distributed output cache.

For example, when the development team applies a change to a template and deploys this to production. The deployment causes an application restart and, in case of in-memory output cache, the cached HTML of the website pages is invalidated, so that the newly deployed changes become visible immediately. With distributed output cache, the application restart does not affect the output cache of pages, therefore you may not see the newly deployed changes to take effect, until you manually publish the page or template, where your widget is placed, or wait for cache to expire.

To assist in situations, where distributed output cache must be invalidated on-demand, Sitefinity CMS exposes a web service for manipulating output cache. By calling the `/restapi/cache/clear` endpoint, website administrators, or authorized users can effectively purge the distributed output cache.

## Use the output cache web service

The output cache web service is available at the `/restapi/cache` endpoint. It supports `POST` requests to the service `/restapi/cache/clear` method. Calling the method invalidates all output cache items stored in distributed cache.

> info  **NOTE**: Clearing all output cache items on a production website might result in a significant performance impact. Avoid doing this if your site is under heavy load.

If you have configured an *Authentication key*, you can pass the key as an HTTP header to the request. The header key must be `SF_OUTPUTCACHE_AUTH`, and its value - the Authentication key value.
