Return to doc.sitecore.com

Caching Layouts

Most Sitecore solutions are very dynamic, generating output for each HTTP request based on a number of factors including session, device, language, authentication, authorization, protocol, domain, path, query string parameters and other variables.  In such dynamic solutions, it is generally preferable to set caching options on individual rendering components which are relatively static.

 

Sitecore provides caching options which allow the rendered data to be retrieved from cache if the data source, device, authentication status, user, rendering parameters and/or query string parameters are the same as the previous request.

 

Whether the rendering is bound to a layout at design time or a placeholder at runtime, the rendering-level caching options allow caching the breadcrumb for a given URL, the login/logout link in the footer based on whether the user has authenticated, the main navigation based on exactly who has authenticated and other components by other criteria.

 

Chances that the same combination will be repeatedly requested are minor. For this reason caching of entire "pages" - the output of a layout - is disabled by default. This is controlled by the DisableBrowserCaching setting in the web.config file.  When this value is true (the default), the following HTTP headers are inserted into each response:

 

Cache-Control: no-cache, no-store
Pragma: no-cache

 

This disables caching in browsers which access the page and any caching devices between Sitecore and the browser.

 

To enable caching of the output of entire layouts:  

  1. Set DisableBrowserCaching to false in /web.config.
     
  2. Adjust the appropriate OutputCache page directive in the layout(s) which should have output cached.

Once DisableBrowserCaching is set to false, any OutputCache directive in a Sitecore layout gives the same result as it would in any .html page.  This directive is explained in detail by Microsoft Knowledgebase Article 308375 (http://support.microsoft.com/default.html?scid=kb;en-us;323290&LN=ID).