View Database Caches

View Database Caches

Database

  • A named data store for Sitecore items

Database Caches

  • One of the two major sets of caches provided by Sitecore
  • There is a separate cache for each database
  • Provide caching for data, items, paths and standardValues
  • Separate from Site caches, which is the other major set of caches in Sitecore
  • Values set directly on a database will override the values set in <cacheSizes> section
  • Replace dbname with the name of the database, such as “master”or “web”
  • Setting true for CacheOptions.DisableAll on a dataprovider will disable database-level caches for all databases that use that dataprovider

Database Cache Sizes

  • Can be set up on a database definition or specified in the <cachesizes> section
  • Values set directly on a database take precedence over the settings in <cachesizes>

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Caching.CacheManager
  • Sitecore.Caching.DataCache
  • Sitecore.Caching.ItemCache
  • Sitecore.Caching.PathCache
  • Sitecore.Configuration.Settings.Caching
  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Items.Item

Database Cache Configuration

  • <configuration>
    • <sitecore>
      • <databases>
        • <database id="dbname" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
          • <cacheSizes hint = "setting">
            • <data> 20MB</data>
            • <items> 10MB</items>
            • <paths> 500KB</paths>
            • <standardValues> 500KB</standardValues>

C# Web Control Code

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

Sitecore.Caching.ItemCache dbItemCache = Sitecore.Caching.CacheManager.GetItemCache(db);
Sitecore.Caching.DataCache dbDataCache = Sitecore.Caching.CacheManager.GetDataCache(db);
Sitecore.Caching.PathCache dbPathCache = Sitecore.Caching.CacheManager.GetPathCache(db);
string defaultPathCacheSize = Sitecore.Configuration.Settings.Caching.DefaultPathCacheSize.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.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}", "Item Cache");
output.RenderEndTag(); //P
output.Write("{0}&#63;&#160;{1}", "Item Cache Enabled", "<b>" + dbItemCache.Enabled.ToString() + "</b></br/>");

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

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

output.RenderEndTag(); //Div

C# Web Control Real-time Output

Item: View Database Caches

Item Cache

Item Cache Enabled? True

Data Cache

Data Cache Name: web[data]
Data Cache Enabled? True
Data Cache Maximum Size: 15728640
Data Cache Size: 4401960
Data Cache Default Priority: Normal
Data Cache Space: 11326680
Data Cache Count: 2735
Data Cache Scavengable? False
Data Cache Sync Root: System.Object

Path Cache

Path Cache Name: web[paths]
Path Cache Enabled? True
Path Cache Default Size: 102400
Path Cache Maximum Size: 512000
Path Cache Size: 2298
Path Cache Default Priority: Normal
Path Cache Space: 509702
Path Cache Count: 19
Path Cache Scavengable? False
Path Cache Sync Root: System.Object

Sources