Cache Settings

Cache Settings

Cache Settings

  • Caching can be enabled or disabled in web.config
  • Disable caching during development
  • Remove bugs from all poor performing controls

Sitecore Cache Settings

  • A configuration setting of "false" will disable all caching in Sitecore
  • Sitecore.Configuration.Settings.Caching.Enabled is read-only
  • Use Sitecore.Configuration.Settings.Caching.Enabled to verify whether caching is disabled after updating the web.config file

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Caching.CacheManager
  • Sitecore.Caching.DataCache
  • Sitecore.Caching.HtmlCache
  • Sitecore.Caching.ItemCache
  • Sitecore.Caching.PathCache
  • Sitecore.Caching.RegistryCache
  • Sitecore.Caching.ViewStateCache
  • Sitecore.Caching.XslCache
  • Sitecore.Configuration.Settings.Caching
  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Items.Item
  • Sitecore.Sites.SiteContext
  • Sitecore.StringUtil

Cache Configuration Settings

  • <configuration>
    • <sitecore>
      • <settings>
        • <setting name="Caching.Enabled" value="true"/>

Cache Settings C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Caching.ItemCache itemCache = Sitecore.Caching.CacheManager.GetItemCache(db);
Sitecore.Caching.DataCache dataCache = Sitecore.Caching.CacheManager.GetDataCache(db);
Sitecore.Caching.PathCache pathCache = Sitecore.Caching.CacheManager.GetPathCache(db);

Sitecore.Sites.SiteContext site = Sitecore.Context.Site;
if (site == null) return;

Sitecore.Caching.HtmlCache htmlCache = Sitecore.Caching.CacheManager.GetHtmlCache(site);
Sitecore.Caching.RegistryCache regCache = Sitecore.Caching.CacheManager.GetRegistryCache(site);
Sitecore.Caching.ViewStateCache viewCache = Sitecore.Caching.CacheManager.GetViewStateCache(site);
Sitecore.Caching.XslCache xslCache = Sitecore.Caching.CacheManager.GetXslCache(site);

string cachingEnabled = Sitecore.Configuration.Settings.Caching.Enabled.ToString();
string cacheMgrEnabled = Sitecore.Caching.CacheManager.Enabled.ToString();
string totalCount = Sitecore.Caching.CacheManager.GetStatistics().TotalCount.ToString();
string totalSize = Sitecore.Caching.CacheManager.GetStatistics().TotalSize.ToString();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using &#58; for colon and &#63; for question mark and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Item", displayName);
output.RenderEndTag(); //P

output.Write("{0}&#63;&#160;{1}", "Caching Enabled", "<b>" + cachingEnabled + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Cache Manager Enabled", "<b>" + cacheMgrEnabled + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Total Caching Count", "<b>" + totalCount + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Total Caching Size", "<b>" + totalSize + "</b>");

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}", "Database Caches");
output.RenderEndTag(); //P

output.Write("{0}&#63;&#160;{1}", "Item Cache Enabled", "<b>" + itemCache.Enabled + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Data Cache Enabled", "<b>" + dataCache.Enabled + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Path Cache Enabled", "<b>" + pathCache.Enabled + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Standard Values Cache Enabled", "<b>" + db.Caches.StandardValuesCache.Enabled + "</b><br/><br/>");

output.Write("{0}&#58;&#160;{1}", "Data Cache Count", "<b>" + dataCache.InnerCache.Count.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Path Cache Count", "<b>" + pathCache.InnerCache.Count.ToString() + "</b><br/>");

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}", "Site Caches");
output.RenderEndTag(); //P

output.Write("{0}&#63;&#160;{1}", "Html Cache Enabled", "<b>" + htmlCache.Enabled + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Registry Cache Enabled", "<b>" + regCache.Enabled + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "ViewState Cache Enabled", "<b>" + viewCache.Enabled + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Xsl Cache Enabled", "<b>" + xslCache.Enabled + "</b><br/><br/>");

output.Write("{0}&#58;&#160;{1}", "Html Cache Count", "<b>" + htmlCache.InnerCache.Count.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Registry Cache Count", "<b>" + regCache.InnerCache.Count.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "ViewState Cache Count", "<b>" + viewCache.InnerCache.Count.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Xsl Cache Count", "<b>" + xslCache.InnerCache.Count.ToString() + "</b><br/>");

output.RenderEndTag(); //Div


Cache Settings C# Web Control Output

Access Result Cache Size: 2097152
Average Item Size: 5000
Blob ID Cache Size: 512000
Caching Enabled? True
Default Client Data Cache Size: 5242880
Default Data Cache Size: 10485760
Default Filtered Items Cache Size: 2097152
Default HTML Cache Size: 5242880
Default Item Cache Size: 10485760
Default Path Cache Size: 102400
Default Client Data Cache Size: 5242880
Default Priority: Normal
Default Property Cache Size: 512000
Default Proxy Cache Size: 512000
Default Template Cache Size: 5242880
Default ViewState Cache Size: 5242880
Default XSL Cache Size: 10485760
HTML Lifetime: 00:00:00
Huge Cache Size: 104857600
Is User In Role Cache Size: 1048576
Item Caching Enabled? True
Large Cache Size: 10485760
Load Factor: 1
Maximum Load Factor: 3
Medium Cache Size: 1048576
Scavenge Interval: 00:03:00
Small Cache Size: 102400
Standard Values Default Cache Size: 1048576
Standard Values Cache Average Value Size: 100
Tiny Cache Size: 10240
User Profile Cache Size: 1048576
ViewState Cache Enabled? True

Sources