Sitecore Output Caching in MVC

Sitecore can cache the output of any presentation component that it is aware of Renderers.  It provides us an option to use caching for renderings to improve system performance and response time.

Below are the Steps that provides you more information on configuring caching on Renderers (i.e. View Renderers / Controller Renderers) in my example:

Remember that you have to mark each rendering as Cacheable to get Sitecore to cache its output, and that Sitecore will only cache output when running that rendering in the context of a managed site for which the cacheHtml attribute is true.

Before invoking the rendering, Sitecore calculates the cache key based on current processing conditions. If an entry with that key exists in the cache, Sitecore renders that result; otherwise, it invokes the rendering and adds the entry to the cache.

Cache Key is only generated if the rendering is marked as cacheable. Output cache keys always contain something to identify the rendering component.

For every rendering request, Sitecore runs a processor to generate a cache key based on the selected VaryBy options using Sitecore.Mvc.Pipelines.Response.RenderRendering.GenerateCacheKey located in Sitecore.MVC assembly and defined in Sitecore.MVC.config.

VaryByData: Vary by Data being checked then it stores cachekey something like this  “Renderer Component” # “Lang Current Culture” # “Data (DataSource)” . Use VaryByData for renderings that generate different output for different data source items. For Example Personalization rules maps to different DataSources based on conditions.

VaryByLogin: VaryByLogin tracks only two states: anonymous and authenticated.We can output different cache keys based on if user is logged in or not.

VaryByUser: You can use VaryByUser for renderings that generate different output for different authenticated users.

VaryByParam: If you pass parameters to renderings, you can use VaryByParm to include those parameters in the cache key.

VaryByQueryString:VaryByQueryString option to add all query string keys and values to the cache key.

VaryByDevice: You can use the VaryByDevice option to generate different cache entries for a single rendering invoked in the context of different Sitecore devices.

ClearOnIndexUpdate: ClearOnIndex indicates entries that Sitecore should remove from output caches after search index rebuilding operations complete.

You can clear the cache using [HOST_NAME]/sitecore/admin/cache.aspx