Friday, February 23, 2018

Sitecore caching overview

Sitecore has three main databases:-
  • Core
  • Master
  • Web
There can be different instances connected to these databases depending up on your set up, for example 1 Content Authoring and 2 Content Delivery instances.

There are three types of caches in Sitecore:
  • Item Cache
  • Data Cache 
  • Prefetch Cache
Caching mechanism is same for all the databases. 

Lets discuss how the caching works. 

All the content in Sitecore exist in Master database in the different tables like Item Tables. There are other tables as well for items versions, for shared versions. Whenever there is request for a content item using Sitecore Data API, Sitecore has to run a query against these tables to return the result. Now running these queries every time is an expensive operation in case of no change in the item.

So initially all the caches are empty. But once a request for a data item comes, Sitecore runs a query on database to get the item and then fill it in the Prefetch cache first and then to Data Cache and then in item Cache. Now when the next request comes for the item it checks it in cache and return the result.

Now as you have two Content delivery instances having all these caches filled, how will these instances determine if any item has changed?

For this there is a provision of Event Queue table. Each database has an event queue table. When any item is changed and published an entry will be done in the event queue table. Each CD instance has a event processing thread which runs every 2 sec. It scans the event queue table for the last time stamp it scanned the Event Queue table. If there are any new records it checks the cache and see if these records refer to any item in the cache. If yes it deletes them from the cache, so that on next request for Item it will bring the item from database.

No comments:

Post a Comment