Output cache web service
The Sitefinity CMS output cache implementation guarantees your sites perform optimally and can handle peaks in user load. When you use distributed output cache, the items, stored in the output cache, remain available even during website restart or IIS AppPool recycle.
For more information, see Distributed output cache
The above described behavior is beneficial for your website performance and is one of the main advantages of distributed output cache. In some cases, however, you might want to have a mechanism for on-demand invalidation of distributed output cache. Let's take, for example, a case when you apply a change to an MVC view or template, and deploy this on production. The deployment causes an application restart, and in the case of in-memory output cache, the cached HTML of the website pages is invalidated, thus the newly deployed changes will become visible immediately. With distributed output cache, the application restart does not affect the output cache of pages, thus you might not see the newly deployed changes take effect until you manually publish the page or template, where your widget is placed, or wait for cache to expire naturally.
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.
Setting up the output cache web service
By default, the output cache web service is disabled. To enable and configure it, follow these steps:
- From the Sitefinity CMS administrative backend, navigate to Administration » Settings » Advanced.
- Using the left-hand navigation, select System » Output Cache Settings » Output cache web service.
- On the next screen select the Enable output cache web service checkbox.
- Optionally, configure the following properties:
- Authentication key - By default, requests to the output cache web service are possible only for authenticated users members of the Administrators role. If you want to enable non-Administrators to access the service endpoint, you can configure an authentication key. Type in the desired key in the textbox. Later, when making calls to the service, pass the value of the Authentication key textbox as an HTTP header with key
- Require Https for all requests - By default, this setting is enabled. it controls whether all web service calls should be redirected to
https:// or not. For optimal security, keep this setting enabled, unless your specific use case scenario requires that you make the web service calls to the output cache web service over
- Click on Save Changes to persist your settings.
Use the output cache web service
The output cache web service is available at the
/restapi/cache endpoint. It supports only POST requests to the service
/restapi/cache/clear method. Calling the method effectively invalidates all output cache items stored in distributed cache.
To use this method, you need to specify
Content-Type: application/json in the headers of your REST call.
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.
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.