Path Cache

Path Cache

Path Mappings

  • Sitecore uses GUIDs to locate and retrieve all items
  • Sitecore maps each item path (/sitecore/content/home) to a particular item ID (GUID) 
  • These mappings are cached in the Path cache

The Path Cache

  • Stores mappings about previously resolved paths
  • Provides faster retrieval of previously requested content items

Path Cache Configuration

  • Assigned to a specific database in the <databases> section of the web.config
  • <paths> in the path specifies the path cache used by items of that database
  • SeDBName in the path can be "web", "master", "core" or "filesystem"

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

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

Configuration Settings

Database Setting

  • <configuration>
  •   <databases>
  •     <database id="DBName" singleinstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
  •            <paths>500KB</paths>

 

Default Setting

  • <configuration>
  •    <settings>
  •       <setting name="Caching.DefaultPathCacheSize" value="100KB"/>

 


C# Web Control Code

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

Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Caching.PathCache pathCache = Sitecore.Caching.CacheManager.GetPathCache(db);
if (pathCache == 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);
//using &#58; for colon and &#63; for question mark and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

string defaultPathCacheSize = Sitecore.Configuration.Settings.Caching.DefaultPathCacheSize.ToString();

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

output.RenderEndTag(); //Div

Path Cache C# Web Control Output

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

Sources