TreeCache

From Sense/Net Wiki
Jump to: navigation, search
  •  
  •  
  •  
  •  
  • 100%
  • 6.4 Patch 1
  • Enterprise
  • Community
  • Planned

Overview

Sense/Net ECM stores all data in the Content Repository in a huge tree built of Content items. There are features that require caching certain types of content from all over this Content tree. For example Settings content can be stored (almost) anywhere in the system and need to be accessed quickly very often. This article describes the technique of caching content in a tree structure for developers.

This is a feature designed for experienced developers. Please consider carefully before trying to use this API.

Details

Tree cache lets developers create a cache module that targets a specific feature and lets you access cached items in a certain subtree using a fast parent-child relationship cache method. For example when a certain setting needs to be accessed in a document library, we turn to the Settings cache (that builds on Tree cache) to find the setting content that applies in that part of the Content Repository - even if it is defined on a higher level or globally.

Tree cache features

The abstract base class TreeCache is a generic class that provides the algorithms for caching and retrieving the items. It also takes care of invalidation, even in an NLBS environment, you do not have to worry about multiple web servers. The main responsibility of the Tree cache module is only to provide you with the nearest available item in the tree so you do not have to make a parent walk and look for Content items yourselves.

The base class actually does not cache real Content items, only identifiers and parent-child relationships, because caching actual Content is the responsibility of the main system cache. This means you can freely use this module even with a relatively huge number of cached items.

Custom tree cache implementation

If you as a developer want to create a custom tree cache implementation, you are only responsible for defining the method of collecting the items to cache and for providing an API for others to access these cached items.

Examples

The following is a simplified example for accessing cached items. Please refer to the SettingsCache class for a more detailed example.

var tnode = settingsCacheInstance.FindNearestItem(contextPath,
   p => RepositoryPath.Combine(p, SETTINGSCONTAINERNAME, name + "." + EXTENSION));
 
if (tnode != null)
   return Node.Load<T>(tnode.Id);

In the example above you can see how you find the exact cached item that applies to a certain point in the Content Repository tree. These are the parameters:

  • Context path: a starting point, e.g. the current document or library.
  • Transform function: the path transform method specifically designed for your feature. For example in case of settings we are looking for a Settings content on the current level that has a path like [context path]/Settings/[settings name].settings.

After you have the appropriate item, you should load the corresponding Content from the main cache and return it to the caller.

Related links

References

There are no related external articles for this article.