Sitecore Cache

Caching plays a very important role in website performance. Sitecore has many cache layers and the most important ones are described in this post. Moreover, I will explain on how to clear specific cache programmatically.

Sitecore Most Important Cache Layers

1. Prefetch Cache

In simple words, Prefetch Cache is data being pulled out from the database at Sitecore startup. All items that require to be loaded on Sitecore startup is set into the different configuration files found in the App_Config\Prefetch.

2. Data Cache

The Data Cache stored items of the Sitecore class ItemInformation. Its main functionality is to reduce the number of requests to the database. It get filled-in whenever they are requested. The process for it to get populated is when fetching item from the Prefetch Cache. In other words, the Prefetch Cache fills the Data Cache. The default Data Cache size is 10MB for Sitecore v7.x and 50MB for Sitecore v8.x and can be configured in the web.config. Moreover, it can be set per database.

3. Item Cache

Item Cache stores objects created from the class Sitecore.Data.Items.Item. This is mainly used in the code. The presence of this cache is to minimize the number of request the ItemInformation needs to make to the Prefetch Cache.

4. HTML Cache

Th HTML Cache is present on the Properties window when configuring / editing a subalyout. It is mainly used when you have lots of processing to perform in order to render the page. A simple example is when you are looping into a large number of items and rendering each one of them.

Configuring the Caching

Prefetch Cache is configured per database and you can set the different Item IDs that you require to load on Sitecore startup.

Data Cache is configured per database. The settings by default are found in the web.config and for Sitecore 8, they are found in the Sitecore.config (Website\App_Config\)

Pref 7

Sitecore 7.X

pref 8

Sitecore 8.X

 Configuring Data Cache and Item Cache are configured same place

Item 72

Sitecore 7.X

Item 8

Sitecore 8.X

For the HTML Cache, you just need to have the Properties table opened and select the different caching that suit your needs. The configuration is found in the <site> tag since the cache is set per site.


Populating the Cache Layers

Each cache layer will be populated from the values from the previous cache level if empty. Prefetch Cache is populated from the Database. Data Cache is populated by the Prefetch Cache. Item Cache is populated by Data Cache and HTML Cache is populated from the Data Cache.


Clear Sitecore Cache per Site

When using the Sitecore cache.aspx, it will clear all the cache. Due to this, Sitecore will fetch again the items and populate the cache layers again. This can reduce the performance of the site since fetching all the required items from the database will increase the number of requests sent to the database. In this section, I will explain on how to clear the Sitecore cache per site.

Using the Cache Manager, you can easily retrieve all the caches that are being used by Sitecore.

//Get all the cache
var caches = CacheManager.GetAllCaches();

Then, looping in the caches, you can check the name if it matches the your Site name. Note that the cache name is taken from the SiteDefinition.config.

var caches = CacheManager.GetAllCaches();
foreach (var cache in caches)
    if (cache.Name.ToLower().Contains("mysitename"))

 You can extend the Sitecore cache.aspx and insert a textbox in which you specify the cache you need to clear.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s