Kentico CMS 7.0 Developer's Guide

Caching options

Caching options

Previous topic Next topic Mail us feedback on this topic!  

Caching options

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Cache is a storage space which duplicates commonly used data to provide faster access to the data. Kentico CMS stores all its data in an SQL database, which requires the application to connect to the SQL server and transfer data over ineffective lines. This is why the application has a built-in cache, which copies the data that it uses the most to the application memory, and then retrieves the data from the memory instead of the database.

 

Cache types

 

Kentico CMS provides the following types of caching:

 

Content cache - stores data used by web parts and controls that display structured content, such as repeaters and listings.

Files cache - stores images. Supports both server and client-side caching

Output cache (full page) - caches the full HTML output of pages.

Page info cache - stores the basic information about documents, such as document's name and properties.

Partial cache - caches the HTML output of specific web parts or controls.

 

Enabling page info cache

 

When a visitor requests a page, the system first queries the database for information about the page. Page info cache allows the system to send the queries only once and serve the results from the application's memory the next time. The basic page information includes:

 

alias path

ID and name

metadata

properties

SKU information

workflow information

 

For the full list of database columns that the page info cache stores, see View_CMS_Tree_Joined in the database reference.

 

To enable page info cache:

 

1. Open Site Manager and go to Settings -> System -> Performance.

 

2. Type a number of minutes into the Cache page info (minutes) setting. This is how long the cache will retain a particular page info item.

 

3. Save the settings.

 

When you request a page, its basic info will be stored in the cache. You can check that in the cache debugging interface. The cache keys begin with "pageinfo" or "pageinfobyurl". The information stays in the cache for the amount of time you specified in the Cache page info setting, or until someone modifies the related document.

 

Enabling content cache

 

Content cache helps the system to ease the load on SQL servers by storing structured data in the application's memory. You can set it up on two levels - either on a global level, which influences a whole site, or you can enable content cache for individual instances of web parts.

 

To enable content cache globally:

 

1. Open Site Manager and go to Settings -> System -> Performance.

 

2. Type a number of minutes into the Cache content (minutes) setting. This is how long the cache will retain cache items.

 

3. Save the settings.

 

With content cache enabled globally, the system stores structured data displayed by all web parts such as repeaters or listings. The data stays in the cache for the amount of time specified in the Cache content setting.

 

To enable content cache for particular web part instances:

 

1. Edit the web part in design mode.

 

2. Type a number of minutes into the Cache minutes property. This is how long the cache will store the web part's data.

oThe Cache minutes property is only available for web parts that load structured data from the database (i.e. data sources).

 

3. (Optional) Define Cache dependencies.

 

4. Click OK to save the web part's properties.

 

With content cache enabled, the system stores data displayed by the particular web part instance. The data stays in the cache for the amount of time specified in the Cache minutes property.

 

To disable content cache for a particular web part when content cache is globally enabled:

 

1. Edit the web part in design mode.

 

2. Type 0 (zero) into the Cache minutes property.

 

3. Click OK to save the web part's properties.

 

When you disable content cache for a particular web part, it doesn't store any of its structured data in the cache.

 

Enabling files cache

 

The system supports two types of file caching:

 

Server-side - stores images in the application's memory so that the CMS doesn't have to access the database and file system every time an image is requested.

Client-side - uses HTTP request headers to control file caching in client browsers and intermediate network caches.

 

To enable server-side file caching:

 

1. Open Site Manager and go to Settings -> System -> Performance.

 

2. Type a number of minutes into the Cache images (minutes) setting. This is how long the cache will retain images.

 

3. Save the settings.

 

With files cache enabled, the system stores images in the memory when they are requested. On subsequent requests, the system serves the images from the memory. Images stay in the cache for the amount of time specified in the Cache images setting.

 

 

InfoBox_Note

 

Please note

 

Even when the files cache is off, the system still caches images for one minute to prevent the application from overloading in case of a DoS attack.

 

 

To enable client-side file caching:

 

1. Open Site Manager and go to Settings -> System -> Performance.

 

2. Type a number of minutes into the Client cache (minutes) setting. This determines the expiration time in the client cache.

 

3. Save the settings.

 

With client cache enabled, the system allows browsers to cache files for the number of minutes specified in the Client cache setting.

 

Enabling output cache

 

The most effective way to increase website performance is output cache. Output cache stores the full HTML source of pages. This way the application doesn't have to communicate with SQL servers and process data every time a page is requested.

 

This option is not suitable for pages with web parts that need to be refreshed very often (e.g., the Random document web part) since you cannot disable caching for particular web parts. For such pages, it's recommended that you do not use output caching and use content caching instead.

 

If you wish to use output cache, you need to enable it globally in settings and then enable it for specific documents. Documents can inherit output cache settings from their parent document.

 

To allow output cache globally:

 

1. Open Site Manager and go to Settings -> System -> Performance.

 

2. Set Enable output caching to true.

 

3. Save the settings.

 

To enable output cache for documents:

 

1. Open the document's properties and select the General tab.

 

oTo apply output caching on all documents on your site, select the root document. Note that the underlying documents need to have the Use output cache property set to Inherit.

 

2. In the Output cache section, select Yes next to Use output cache.

 

3. Type a number of minutes into Cache minutes.

 

4. Save Save the document.

 

When a page is requested, the system stores its HTML source into the output cache. The data stays in the cache for the amount of time specified in Cache minutes or until someone modifies the page. However, if the page displays other documents (such as a news list) and you modify these documents, the page will stay in the cache and won't be updated until the cache expires.

 

Enabling partial cache

 

Partial cache stores the HTML output of web parts and controls as individual cache items. You can use partial cache when full page output caching is not feasible.

 

To allow partial caching globally:

 

1. Open Site Manager and go to Settings -> System -> Performance.

 

2. Set Enable partial caching to true.

 

3. Save the settings.

 

The website now allows partial caching for web parts and controls. By default, web parts do not use partial caching and you need to enable it for individual instances.

 

To enable partial caching for particular web part instances:

 

1. Edit the web part's properties.

 

2. Locate the Performance section and type a number of minutes into the Partial cache minutes property.

 

3. Specify cache dependencies.

 

4. Click OK.

 

When a page containing the web part is requested, the system stores the HTML output of the web part into the cache. The data stay in the cache for the amount of time specified in Partial cache minutes or until a dependent object is modified.

 

Cache dependencies

 

Cache dependencies allow the application to clear cached data based on relationships with other objects. A cache dependency is represented by a dummy cache key (a cache item that doesn't contain any data) that identifies an object or a set of objects. When an object that matches the dummy key is modified, the dummy key is "touched" and all cache items depending on the dummy key are removed from the cache.

 

For example, you have a page (with alias path /Products) that contains a repeater. The repeater displays a list of products that reside under the Products page. Only the content cache is turned on. A visitor requests the Products page, the repeater fetches the products from the database and stores them in the cache. The system also creates the following dummy key: node|corporatesite|/products|childnodes. The dummy key ensures that once a child node of the Products node is modified, the depending cache items get cleared.

 

Entering custom cache dependencies

 

You can use cache dependencies to specify conditions that should be met in order to delete a web part's output from the memory. Each web part has its default dependencies which include all possible object changes that the content of the web part could depend on.

 

Note: The following steps describe how to specify dependencies for partial cache. Before you specify partial cache dependencies, enable partial caching for the given web part.

 

You can also define custom dependencies for output cache of a page using the Output cache dependencies web part.

 

To specify custom cache dependencies for partial cache:

 

1. Open the web part's properties.

 

2. Locate the Performance section.

 

3. Type one dummy key per line into the Partial cache dependencies field.

 

The following table shows which dummy cache keys get touched when an object gets changed. The table also lists examples of the dummy keys.

 

Object

Touched keys

Sample values

Document

(TreeNode)

node|<sitename>|<aliaspath>|<culture>

node|<sitename>|<aliaspath>

nodeid|<nodeid>

nodeid|<linkednodeid>

nodes|<sitename>|<classname>|all

+ for every parent node:

node|<sitename>|<aliaspath>|childnodes

node|corporatesite|/home|en-us

node|corporatesite|/home

nodeid|12

nodeid|34

nodes|corporatesite|cms.menuitem|all

 

node|sitename|/|childnodes

Any object

(except documents)

<classname>|all

<classname>|byid|<id>

<classname>|byname|<codename>

<classname>|byguid|<guid>

cms.user|all

cms.user|byid|53

cms.user|byname|administrator

cms.user|byguid|1ced44f3-f2fc- ...

Metafile

metafile|<guid>

metafile|1ced44f3-f2fc- ...

Document attachment

attachment|<guid>

attachment|1ced44f3-f2fc- ...

Forum attachment

forumattachment|<guid>

forumattachment|1ced44f3-f2fc- ...

Avatar

avatarfile|<guid>

avatarfile|1ced44f3-f2fc- ...

Media file

mediafile|<guid>

mediafile|preview|<guid>

mediafile|1ced44f3-f2fc- ...

mediafile|preview|1ced44f3-f2fc- ...

Page template

template|<id>

template|12

CacheHelper

.ClearFullPageCache

fullpage

fullpage

 

Example 1: you have a web part displaying some information about users. Therefore, whenever some user gets their details modified, the web part's cache should be cleared. To ensure this, you need to enter cms.user|all into the field, which is the dummy key that would get touched whenever some user's details get changed.

 

Example 2: your web part is displaying information about one particular user - the administrator. Their user name is administrator, ID is 53 and GUID is something beginning with 1ced44f3-f2fc. So if you want to have the cache cleared whenever this user's details are changed, you can use any of the following three keys that identify the user by the previously named properties:

 

cms.user|byid|53

cms.user|byname|administrator

cms.user|byguid|1ced44f3-f2fc-...

 

Clearing the cache

 

Kentico CMS allows you to clear the contents of its cache.

 

To delete all items from the cache:

 

1. Go to Site Manager -> Administration -> System.

 

2. Click Clear cache.

 

The system empties the cache, including all dummy keys.

 

To delete a particular page from the output cache:

 

1. Select the document in CMS Desk content tree,

 

2. Navigate to Properties -> General.

 

3. Click Clear output cache in the Output cache section.

 

The system deletes the document's HTML output from the cache.

 

Debugging cache

 

The system debugging interface in Site Manager -> Administration -> System allows you to see the list of items that are in the system's cache and the list of dummy keys (cache dependencies). You can also view what cache operations the system performed when serving a particular page request.

 

Reference: Cache settings


 

Global

 

The following cache settings are available in CMS Site Manager -> Settings -> System -> Performance:

 

Server content caching

Cache page info (minutes)

Sets the number of minutes for which the system caches page information. This option caches page properties and metadata. Kentico CMS retrieves page information many times during the processing of a single page, so always set this value to at least 10 minutes!

 

When a page is modified, the system automatically clears the corresponding part of the page info cache, so the website will not display outdated information.

Cache content (minutes)

Sets the number of minutes for which all web parts/controls cache the content that they retrieve from the Kentico CMS database.

 

You can override this value for specific web part instances by setting their Cache minutes property. Using 0 as the value disables content caching for the given web part instance.

 

It is recommended to cache all possible content that is not modified often. The drawback of this option is that if content is modified, the changes appear on the live site only after the old version expires in the cache.

Use progressive caching

If checked, the system optimizes access to uncached data so that concurrent threads only use a single data access operation and share the results. This leads to better performance if the website is under a heavy load, without the drawback of not having the latest data available.

Server file caching

Cache images (minutes)

Sets the number of minutes for which the system caches image files on the server.

 

It is recommended to always use image caching. Kentico CMS automatically removes images from the cache if they are modified, so image caching cannot cause the website to display outdated content.

Maximum file size to cache

Specifies the maximum file size in kilobytes that is allowed to be cached.

Redirect files to disk

If checked, file requests are redirected to the corresponding physical file in the file system if possible.

File client caching

Client cache (minutes)

Sets the number of minutes for which client browsers are allowed to cache files.

 

If the value is 0, client caching for files is disabled.

Client cache must revalidate

If enabled, client browsers need to revalidate cached content by calling the server. If disabled, browsers do not perform server requests if the requested content is already cached.

Output caching

Enable output caching

If checked, the system allows output caching. Output cache stores the full HTML source of pages. If unchecked, output caching is disabled on the whole website.

 

To enable output caching for pages, configure the Output cache properties of individual documents in CMS Desk on the Properties -> General tab. Both the main website setting and document settings must be enabled to use output caching.

Cache output in file system (minutes)

Specifies the number of minutes for which the system stores output cache in the file system. This provides persistent cache storage in case of application restarts.

 

If not set, only the standard caching mechanism (in memory) is used. If you enter a value, the system checks both types of cache.

 

To enable output caching in the file system for pages, configure the Allow file system cache property of individual documents in CMS Desk on the Properties -> General tab.

Enable partial caching

If checked, the system allows partial caching of web parts and controls. The partial cache stores the HTML output of individual web part or control instances. If unchecked, partial caching is disabled on the whole website for all web parts.

 

By default, web parts do not use partial caching and you need to enable it for individual instances using their Partial cache minutes property.

 

Documents

 

Individual documents have the following output cache settings in CMS Desk on the Properties -> General tab:

 

Output cache

Use output cache

Indicates if the system caches the full HTML output of the page. Output caching can greatly improve the performance of the page, but is not suitable for pages with dynamic content.

 

You can inherit the output cache settings from the parent document.

 

Important: Output caching must also be allowed in the website's settings. Administrators can enable output caching in Site Manager -> Settings -> System -> Performance.

Cache minutes

Determines how long the system keeps the output code of the page in the cache (if output caching is enabled).

 

The page's output cache is automatically cleared if someone modifies the page. You can manually remove the page from the output cache by clicking Clear output cache.

Allow file system cache

Indicates if the system stores the page's output cache on the server's file system. This provides persistent caching in case of application restarts.

 

If disabled, the application only caches the page output in its memory. If enabled, the system checks both types of cache.

 

You can inherit the setting from the parent document.

 

The file system cache is stored for the number of minutes specified in the Cache output in file system (minutes) setting in Site Manager -> Settings -> System -> Performance.

 

Web parts

 

Instances of web parts provide the following properties for configuring content caching and partial output caching:

 

System settings

Cache item name

Sets the name of the cache key used for the content of the web part. If not specified, this name is generated automatically based on the site, document path, Web part control ID and current user.

 

A cache key can be shared between multiple web parts displaying the same content on different pages in order to avoid keeping redundant data in the memory.

Cache minutes

Sets the number of minutes for which the content of the web part remains cached before the latest version is reloaded from the database.

 

If empty, the web part uses the value entered into the Site Manager -> Settings -> System -> Performance -> Server content caching -> Cache content (minutes) setting.

 

If set to 0, the web part does not use content caching.

Cache dependencies

Contains a list of cache keys on which the content cache of the web part depends. When the specified cache items change, the content cache of the web part is deleted. Each line may only contain a single item.

 

If you check Use default cache dependencies, the web part uses dependencies that include all possible object changes that could affect the content of the given web part.

Performance

Partial cache (minutes)

Sets the number of minutes for which system caches the output HTML code of the web part. Partial caching is similar to to full-page caching, but only for the code of the web part specifically.

 

If left empty or set to 0, partial caching is not used for the web part.

 

Important: Partial caching must also be allowed in the website's settings. Administrators can enable partial caching in Site Manager -> Settings -> System -> Performance.

Partial cache dependencies

Allows you to specify a list of cache keys on which the partial cache of the web part depends. When the specified cache items change, the system clears the partial cache of the web part. Each line may only contain a single item.

 

If you check Use default cache dependencies, the web part uses dependencies that include all possible object changes that could affect the given web part.