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:

  1. From the Sitefinity CMS administrative backend, navigate to Administration » Settings » Advanced.
  2. Using the left-hand navigation, select System » Output Cache Settings » Output cache web service.
  3. On the next screen select the Enable output cache web service checkbox.
  4. Optionally, configure the following properties:
    1. 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 SF_OUTPUTCACHE_AUTH.
    2. 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 http://.
  5. 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.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

Sample queries