Sitecore 8.2 Cache Changes

Sorry – it’s been a while. The school holidays happened! I thought I’d ease myself back in to the blogging with some changes that Sitecore have introduced with Sitecore 8.2 (specifically some changes to the Caching stuff).

We’ve got some helper methods which handle adding and removing stuff from the Sitecore Cache (or optionally A N Other cache).

All was working fine and dandy until the Sitecore 8.2 upgrade. Here’s what we had to change (other changes may be necessary for your solution).

Change 1: Interfaces! 🙂

private Sitecore.Caching.Cache SitecoreCache(bool isGlobal = false, string siteName = "website", string databaseName = "master")


private ICache SitecoreCache(bool isGlobal = false, string siteName = "website", string databaseName = "master")

Hooray! Sitecore have started using Interfaces. So their GetNamedInstance method has started returning that Interface instead of a concrete Cache item. Happy days.

But wait! Where has GetNamedInstance gone?

Change 2: CacheManager not Cache

This line:

cache = Sitecore.Caching.Cache.GetNamedInstance(cacheKey, Sitecore.StringUtil.ParseSizeString(Sitecore.Configuration.Settings.GetSetting("Caching.CacheSize", "100MB")));

Became this:

cache = Sitecore.Caching.CacheManager.GetNamedInstance(cacheKey, Sitecore.StringUtil.ParseSizeString(Sitecore.Configuration.Settings.GetSetting("Caching.CacheSize", "100MB")), true);

This seems to work – although I’ll be doing a spot more testing before we go to production 😉 Notice the change to the class referenced and also the additional “true” this is to say that we want to create the cache if it doesn’t exist.

Change 3: No Cache Size on Add

This line no longer appears to work:

cache.Add(key.ToLower(), cachingData, cacheSize, slidingCache, absoluteCache);

It’s because there’s no overload with the cacheSize in any more – I’m guessing that Sitecore is handling this differently now but I’ve made a note for further investigation. So that line becomes:

cache.Add(key.ToLower(), cachingData, slidingCache, absoluteCache);

And finally…

Change 4: GetCacheKeys() Returns Strings

This line:

foreach (object key in cache.GetCacheKeys())

Can now become this:

foreach (string key in cache.GetCacheKeys())

*Opens up the floor for an argument about using “var”*

*Agrees with you*

*Blames code copied from the Internet*

*Goes about his day*

Oh – also make sure you’ve got all your projects set to .Net 4.5.2 at least. And don’t patch in a config with this line:

<database id="master" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">

Because it’s changed to this:

<database id="master" singleInstance="true" type="Sitecore.Data.DefaultDatabase, Sitecore.Kernel">

Use this instead (like the clever people who created Unicorn do):

<database id="master">


3 thoughts on “Sitecore 8.2 Cache Changes

  1. Hello,

    Thank you for this article. I am upgrading from sitecore 8.1 to sitecore 8.2 update 2 and I am getting this error:

    Method not found: ‘Sitecore.Caching.Cache Sitecore.Caching.CustomCache.get_InnerCache()’.

    [MissingMethodException: Method not found: ‘Sitecore.Caching.Cache Sitecore.Caching.CustomCache.get_InnerCache()’.]
    Sitecore.SharedSource.DynamicSites.Caching.SiteCache.Count() in d:\Codes\Sitecore – P3\Dev\Pulse\Modules\Sitecore.SharedSource.DynamicSites\Sitecore.SharedSource.DynamicSites\Caching\SiteCache.cs:77
    Sitecore.SharedSource.DynamicSites.Sites.SwitcherSiteProvider.InitializeCache() in d:\Codes\Sitecore – P3\Dev\Pulse\Modules\Sitecore.SharedSource.DynamicSites\Sitecore.SharedSource.DynamicSites\Sites\SwitcherSiteProvider.cs:47
    Sitecore.SharedSource.DynamicSites.Sites.SwitcherSiteProvider.GetSites() in d:\Codes\Sitecore – P3\Dev\Pulse\Modules\Sitecore.SharedSource.DynamicSites\Sitecore.SharedSource.DynamicSites\Sites\SwitcherSiteProvider.cs:35

    So where can I find the changes that you are referring to?

    Kind Regards,


    1. Hi Adil,

      I would guess on Line 77 in this file: d:\Codes\Sitecore – P3\Dev\Pulse\Modules\Sitecore.SharedSource.DynamicSites\Sitecore.SharedSource.DynamicSites\Caching\SiteCache.cs

      You need to change the reference – it might be that CustomCache is now in Sitecore.Caching.CacheManager (or somewhere else). If you can’t find it – let me know and I’ll have a dig about.

      If you do find it – let me know where it is and I’ll update the blog post for other developers 🙂




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s