Meny NO

Obtaining a cache dependency key

Mari Jørgensen

To improve performance we often cache our view models using methods inside ISynchronizedObjectInstanceCache or IObjectInstanceCache interfaces.

Normally we then want to invalidate the cached model if the current content has changed, i.e. a new version is published.

To achieve this we need to obtain a version cache key using the IContentCacheKeyCreator interface:


However, this will only work if the contentLink provided contains the necessary version info, meaning both the published version and a work id.

The code sample below show how that can be done for catalog node content:

var currentNodeContentLink = _referenceConverter.GetContentLink(catalogNodeId, 
CatalogContentType.CatalogNode, 0); // 0 = published version
var versionCacheKey = GetVersionKey(currentNodeContentLink);


public string GetVersionKey(ContentReference contentLink)
var versionCacheKey = string.Empty;
var latestPublishedVersion = _contentVersionRepository.List(contentLink).ToList()
.FirstOrDefault(v => v.Status == VersionStatus.Published);

if (latestPublishedVersion != null)
// adding current published version to cache key
versionCacheKey = _cacheKeyCreator.CreateVersionCacheKey(latestPublishedVersion.ContentLink);

return versionCacheKey;


Utvikler, Teamleder

Mari Jørgensen

kommentarer drevet av Disqus

More about caching

To read more about caching,
see cache documentation on
Episerver World.