Registry Cache

Registry Cache

Registry Cache

  • A type of site cache unrelated to the caching performed on databases
  • It is assigned under a specific site in the web.config file
  • Used to store user settings not normally used by other applications
  • Size is in bytes or you can append the value with KB, MB or GB
  • Set a size of 0 (zero) to disable

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Caching.CacheManager
  • Sitecore.Caching.RegistryCache
  • Sitecore.Configuration.Settings.Caching
  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • Sitecore.Sites.SiteContext
  • Sitecore.StringUtil

Registry Cache Configuration Settings

Site Setting

  • <configuration>
    • <sitecore>
      • <sites>
        • <site name="shell" xmlcontrolpage="/sitecore/shell/default.aspx" browsertitle="Sitecore" registrycachesize="3MB" />

Default Setting

  • <configuration>
    • <sitecore>
      • <settings>
        • <setting name="Caching.DefaultRegistryCacheSize" value="5MB" />

Registry Cache C# Web Control Code

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

Sitecore.Sites.SiteContext site = Sitecore.Context.Site;
string defaultRegistryCacheSize = Sitecore.Configuration.Settings.Caching.DefaultRegistryCacheSize.ToString();
Sitecore.Caching.RegistryCache registryCache = Sitecore.Caching.CacheManager.GetRegistryCache(site);
if (registryCache == null) return;

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 itemName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using &#58; for colon and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Item", itemName);
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}", "Default Registry Cache Size", "<b>" + defaultRegistryCacheSize + "</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 Maximum Size", "<b>" + registryCache.InnerCache.MaxSize.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Registry Default Priority", "<b>" + registryCache.InnerCache.DefaultPriority.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Registry Cache Remaining 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>");

output.RenderEndTag(); //Div

Registry Cache C# Web Control Output

Item: Registry Cache

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

Sources