Administration: Cache settings
With Sitefinity CMS, you can configure the way your content and pages is cached which affects the overall performance of your system.
You can configure the following types of cache:
- Output cache
Output cache is stored on the server. - Client cache
Client cache is stored on the browser.
Output cache
Output caching happens at the page level (including personalized pages) where Sitefinity CMS caches all rendered output, including widgets. Sitefinity CMS caches a different cache variation for each personalization segment of the page. On widget level, Sitefinity CMS performs cache substitution whenever a widget has an inherent dynamic behavior. For example, this is the case of the login name, login status, and so on. Sitefinity CMS also has output cache for anonymous forum users.
Sitefinity CMS performs post cache substitution – these widgets are written using Razor syntax and right after the cached page is about to be served, Sitefinity CMS injects the string that the widget's HTML output into the response.
Output cache is stored in the memory and is cleared on application start.
You can have only one default cache profile, which is used by default for all pages. You can, however, change the cache profile on page level. Thus, you have different cache behaviors for different pages (sections of your site). Once a page is requested, and if the page is not found on the server output cache, Sitefinity CMS reads the output cache and output cache profile settings to determine whether it should add the page in cache and with what settings. Each consecutive request for the same page is served from cache, unless:
- You configured the page not to use caching
- You disabled output cache globally
- The cache duration of the page has expired or someone has modified it.
This results in invalidation of the cache.
By default, Sitefinity CMS output cache varies by user agent (web browser), meaning that the system creates different cached versions of the page depending on the user agent (web browser) the page is requested from.
Output cache is disabled by default for logged in users that have backend (administrative) access and are browsing the site. Thus, the users can observe the effect of their changes immediately.
Client cache
Sitefinity CMS caches media content (images, documents, videos) on the client browser. By adding a Cache-Control header to the response of the request, the browser can cache the media. As a result, the amount of server request decreases. You can configure any Sitefinity CMS library to use both server caching and client (browser) caching on media content. The expiration of media content in cache is configured by setting the appropriate client cache profile for the library.
Sitefinity CMS combines static resources such as JavaScript and CSS files which can greatly reduce the loading time. By default Sitefinity CMS also enables client caching which allows the browser to cache these web resources for every subsequent request.
In addition, you can configure CDN storage support for media items. For more information, see Use CDN storage for content libraries.
Page compilation caching
Sitefinity CMS supports page compilation caching. For more information, see Tips for optimizing performance » Force pages to compile.
Page compilation caching is stored in ASP.NET temporary folder. This way, it is persistent between restarts.
Database caching
To enable database caching, click Administration » Settings » Advances » Data.
In Enable data caching, enter true or false.
This setting controls the setting of the Open Access 2nd level cache.
In single instance mode, database caching is turned on by default. As of Sitefinity CMS 7.1, in NLB mode database caching is turned on by default, as well.
Custom widgets caching
If your site is configured to use output caching, custom widgets are cached with the entire page. You can disable caching page by page and you can also leverage the post-cache substitution mechanism. Sitefinity CMS exposes a class called CacheSubstitutionWrapper and, if you wanted to inject dynamic content onto cached pages, you can take advantage of this infrastructure without hindering performance.
Caching and permissions
By default, output cache is not invalidated on changing the page permissions.
You can change this by clicking Administration » Settings » Advanced » Pages and deselect Disable Output cache invalidation when permission is changed checkbox. We do not recommend deselecting this option, because any change of permissions will invalidate the output cache of all pages.
Cache expiration
You set cache expiration using the caching profiles, described above. You can the assign different profiles to different pages, using the Advanced options of a page. You can also programmatically expire cache using public void CacheManager.Remove (string key) where key is the ID of the page node.
Output caching for RSS
The output of RSS feeds in Sitefinity CMS is cached the same way as the page output caching.
Output caching in RSS results in less database queries and improves the overall performance of the website.
The RSS caching is not automatically invalidated upon a change in the content that is published in the feed. This means that until the cache expires (sliding or absolute) the feed will not be updated.
The caching profile of the RSS is set for all RSS feeds.
To setup the caching of the RSS feeds, perform the following:
- Create an output caching profile for the RSS feeds.
Perform the following: - In the main menu, click Administration » Settings » Advanced » System » Output Cache Settings » Output Cache Profiles » Create new.
- Enter the setting of the profile.
We recommend using absolute expiration by deselecting Sliding expiration checkbox. Without automatic cache invalidation, sliding expiration can result in very long periods of non-updated feeds. - Click Save changes.
- Assign a caching profile for RSS.
Perform the following: - In the main menu, click Administration » Settings » Advanced » Publishing.
- In Output caching profile to be used for caching the feeds output field, enter the name of the profile that you created.
You can also use one of the existing caching profiles. - Click Save changes.