Return to doc.sitecore.com

Valid for Sitecore 5.3.1
Layout caching in Sitecore

Q:

How can I cache layouts in Sitecore? 

A:

Layouts in Sitecore can be cached in the following way:

  1. Turn off browser cache disabler: <setting name="DisableBrowserCaching" value="false"/>
     
  2. Add "<%@ OutputCache Duration="100" VaryByParam="none" VaryByCustom="itempath" %>" to your layout source.
     
  3. Add the following code to global.asax:
     
    public override string GetVaryByCustomString(System.Web.HttpContext context, string arg)
    {
    string result = string.Empty;

    if ((Sitecore.Context.Item != null) && (arg == "itempath"))
                {
    result = "_#itempath:" + Sitecore.Context.Item.Paths.Path.ToString();
                }
    else
                {
    result = base.GetVaryByCustomString(context, arg);
    }
     
    return result;
    }
      
  4. Comment out the SaveFormAction processor in the web.config file:
    <!-- <processor type="Sitecore.Pipelines.HttpRequest.SaveFormAction, Sitecore.Kernel"/> --> 
    Please note that this setting is already commented out in Sitecore 5.3.1. Build 070417.