View Site Caches

View Site Caches

Site Caches

  • One of the two major sets of caches used by Sitecore
  • Created for each web site separately
  • Provide caching for html, xsl, registry and viewstate
  • Unrelated to the Database caches, which is the other major set of caches in Sitecore
  • The values set directly on a site will override the values set in <cacheSizes> section

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Caching.HtmlCache
  • Sitecore.Caching.RegistryCache
  • Sitecore.Caching.ViewStateCache
  • Sitecore.Caching.XslCache
  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • Sitecore.Sites.SiteContext

Site Caches Configuration Settings

  • <configuration>
    • <sitecore>
      • <sites>
        • <cacheSizes>
          • <sites>
            • <website>
              • <html>10MB</html>
              • <registry>0</registry>
              • <viewState>0</viewState> 
              • <xsl>5MB</xsl>

View Site Caches C# Web Control Code

Sitecore.Sites.SiteContext site = Sitecore.Context.Site; Sitecore.Data.Items.Item item = Sitecore.Context.Item; if (site == null || item == null) return;

Sitecore.Caching.HtmlCache htmlCache = Sitecore.Caching.CacheManager.GetHtmlCache(site); Sitecore.Caching.RegistryCache registryCache = Sitecore.Caching.CacheManager.GetRegistryCache(site); Sitecore.Caching.ViewStateCache viewstateCache = Sitecore.Caching.CacheManager.GetViewStateCache(site); Sitecore.Caching.XslCache xslCache = Sitecore.Caching.CacheManager.GetXslCache(site); Sitecore.Caching.FilteredItemsCache siteFICache = Sitecore.Caching.CacheManager.GetFilteredItemsCache(site);

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 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

if (htmlCache != null) { output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P); output.Write("{0}", "HTML Cache"); output.RenderEndTag(); //P output.Write("{0}&#58;&#160;{1}", "HTML Cache Name", "<b>" + htmlCache.InnerCache.Name + "</b></br/>"); output.Write("{0}&#63;&#160;{1}", "HTML Cache Enabled", "<b>" + htmlCache.InnerCache.Enabled.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "HTML Cache Maximum Size", "<b>" + htmlCache.InnerCache.MaxSize.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "HTML Cache Size", "<b>" + htmlCache.InnerCache.Size.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "HTML Cache Default Priority", "<b>" + htmlCache.InnerCache.DefaultPriority.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "HTML Cache Space", "<b>" + htmlCache.InnerCache.RemainingSpace.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "HTML Cache Count", "<b>" + htmlCache.InnerCache.Count.ToString() + "</b></br/>"); output.Write("{0}&#63;&#160;{1}", "HTML Cache Scavengable", "<b>" + htmlCache.InnerCache.Scavengable.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "HTML Cache Sync Root", "<b>" + htmlCache.InnerCache.SyncRoot.ToString() + "</b>"); }

if (registryCache != null) { output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P); output.Write("{0}", "Registry Cache"); output.RenderEndTag(); //P output.Write("{0}&#58;&#160;{1}", "Registry Cache Name", "<b>" + registryCache.InnerCache.Name + "</b></br/>"); output.Write("{0}&#63;&#160;{1}", "Registry Cache Enabled", "<b>" + registryCache.InnerCache.Enabled.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Registry Cache Maximum Size", "<b>" + registryCache.InnerCache.MaxSize.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Registry Cache Size", "<b>" + registryCache.InnerCache.Size.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Registry Cache Default Priority", "<b>" + registryCache.InnerCache.DefaultPriority.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Registry Cache Space", "<b>" + registryCache.InnerCache.RemainingSpace.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Registry Cache Count", "<b>" + registryCache.InnerCache.Count.ToString() + "</b></br/>"); output.Write("{0}&#63;&#160;{1}", "Registry Cache Scavengable", "<b>" + registryCache.InnerCache.Scavengable.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Registry Cache Sync Root", "<b>" + registryCache.InnerCache.SyncRoot.ToString() + "</b>"); }

if (viewstateCache != null) { output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P); output.Write("{0}", "ViewState Cache"); output.RenderEndTag(); //P output.Write("{0}&#58;&#160;{1}", "ViewState Cache Name", "<b>" + viewstateCache.InnerCache.Name + "</b></br/>"); output.Write("{0}&#63;&#160;{1}", "ViewState Cache Enabled", "<b>" + viewstateCache.InnerCache.Enabled.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "ViewState Cache Maximum Size", "<b>" + viewstateCache.InnerCache.MaxSize.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "ViewState Cache Size", "<b>" + viewstateCache.InnerCache.Size.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "ViewState Cache Default Priority", "<b>" + viewstateCache.InnerCache.DefaultPriority.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "ViewState Cache Space", "<b>" + viewstateCache.InnerCache.RemainingSpace.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "ViewState Cache Count", "<b>" + viewstateCache.InnerCache.Count.ToString() + "</b></br/>"); output.Write("{0}&#63;&#160;{1}", "ViewState Cache Scavengable", "<b>" + viewstateCache.InnerCache.Scavengable.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "ViewState Cache Sync Root", "<b>" + viewstateCache.InnerCache.SyncRoot.ToString() + "</b>"); }

if (xslCache != null) { output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P); output.Write("{0}", "XSL Cache"); output.RenderEndTag(); //P output.Write("{0}&#58;&#160;{1}", "XSL Cache Name", "<b>" + xslCache.InnerCache.Name + "</b></br/>"); output.Write("{0}&#63;&#160;{1}", "XSL Cache Enabled", "<b>" + xslCache.InnerCache.Enabled.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "XSL Cache Maximum Size", "<b>" + xslCache.InnerCache.MaxSize.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "XSL Cache Size", "<b>" + xslCache.InnerCache.Size.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "XSL Cache Default Priority", "<b>" + xslCache.InnerCache.DefaultPriority.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "XSL Cache Space", "<b>" + xslCache.InnerCache.RemainingSpace.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "XSL Cache Count", "<b>" + xslCache.InnerCache.Count.ToString() + "</b></br/>"); output.Write("{0}&#63;&#160;{1}", "XSL Cache Scavengable", "<b>" + xslCache.InnerCache.Scavengable.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "XSL Cache Sync Root", "<b>" + xslCache.InnerCache.SyncRoot.ToString() + "</b>"); }

if (siteFICache != null) { output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P); output.Write("{0}", "Filtered Items Cache"); output.RenderEndTag(); //P output.Write("{0}&#58;&#160;{1}", "Filtered Items Cache Name", "<b>" + siteFICache.InnerCache.Name + "</b></br/>"); output.Write("{0}&#63;&#160;{1}", "Filtered Items Cache Enabled", "<b>" + siteFICache.InnerCache.Enabled.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Filtered Items Cache Maximum Size", "<b>" + siteFICache.InnerCache.MaxSize.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Filtered Items Cache Size", "<b>" + siteFICache.InnerCache.Size.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Filtered Items Cache Default Priority", "<b>" + siteFICache.InnerCache.DefaultPriority.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Filtered Items Cache Space", "<b>" + siteFICache.InnerCache.RemainingSpace.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Filtered Items Cache Count", "<b>" + siteFICache.InnerCache.Count.ToString() + "</b></br/>"); output.Write("{0}&#63;&#160;{1}", "Filtered Items Cache Scavengable", "<b>" + siteFICache.InnerCache.Scavengable.ToString() + "</b></br/>"); output.Write("{0}&#58;&#160;{1}", "Filtered Items Cache Sync Root", "<b>" + siteFICache.InnerCache.SyncRoot.ToString() + "</b>"); }

output.RenderEndTag(); //D

View Site Caches C# Web Control Output

Item: View Site Caches

HTML Cache

HTML Cache Name: website[html]
HTML Cache Enabled? True
HTML Cache Maximum Size: 5242880
HTML Cache Size: 13934
HTML Cache Default Priority: Normal
HTML Cache Space: 5228946
HTML Cache Count: 1
HTML Cache Scavengable? False
HTML Cache Sync Root: System.Object

Registry Cache

Registry Cache Name: website[registry]
Registry Cache Enabled? False
Registry Cache Maximum Size: 0
Registry Cache Size: 0
Registry Cache Default Priority: Normal
Registry Cache Space: 0
Registry Cache Count: 0
Registry Cache Scavengable? False
Registry Cache Sync Root: System.Object

ViewState Cache

ViewState Cache Name: website[viewstate]
ViewState Cache Enabled? False
ViewState Cache Maximum Size: 0
ViewState Cache Size: 0
ViewState Cache Default Priority: Normal
ViewState Cache Space: 0
ViewState Cache Count: 0
ViewState Cache Scavengable? False
ViewState Cache Sync Root: System.Object

XSL Cache

> XSL Cache Name: website[xsl]
XSL Cache Enabled? True
XSL Cache Maximum Size: 1048576
XSL Cache Size: 175
XSL Cache Default Priority: Normal
XSL Cache Space: 1048401
XSL Cache Count: 7
XSL Cache Scavengable? False
XSL Cache Sync Root: System.Object

Filtered Items Cache

Filtered Items Cache Name: website[filtered items]
Filtered Items Cache Enabled? True
Filtered Items Cache Maximum Size: 2097152
Filtered Items Cache Size: 0
Filtered Items Cache Default Priority: Normal
Filtered Items Cache Space: 2097152
Filtered Items Cache Count: 0
Filtered Items Cache Scavengable? False
Filtered Items Cache Sync Root: System.Object

Sources