Take the community feedback survey now.

Daniel Ovaska
Feb 1, 2016
  2294
(0 votes)

Episerver performance–Part 1 Object Cache

When to use object caching

Object caching is great when you are getting data from external systems, like fetching pressreleases from another site like myNewsDesk, getting products from a PIM or similar. These calls are generally very slow and requesting fresh data every time might not be needed.

Memory Cache, Static Dictionary or Episerver Cache

The .NET memory cache in System.Runtime.Caching is a great tool but if you decide to use it, make sure you are not ever going to use load balancing for your websites. To invalidate cache on one server is pretty difficult to get working correctly. For multiple servers, you really want support out of the box like you get with EPiServer Cache.  

A static dictionary can work in a similar way in solutions to store data across calls. The problems here is that you need to be sure that you won’t get into memory problems for storing large amounts of data. Caches have a lot of functionality around this problem. For small amounts of data, storing them in a static dictionary can work but with the same problem with load balancing as above for the standard .NET cache.

Episerver caching now resides under the interesting name ISynchronizedObjectInstanceCache. The old CacheManager is now dead. The new implementation is easy to get from the ServiceLocator and to use and you can follow the guide here:

http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Caching/Object-caching/

I want to highlight a few nice additions they have done. Master keys are new and work like a grouping of cached items. This means that it’s easy to divide your cache into multiple sections like “users”, “products” and similar and only kill the part of the cache you need when something is updated. This is really useful in many scenarios.

To get full benefit from Episervers object caching you also want to configure cache invalidation events for load balanced servers. You can read more about that here

http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Event-management/Event-management/

To cache or not to cache… – Hamlet

Don’t use object caching if you are simply getting current page, getchildren from the CMS. This is cached already 99% of the time so the cost for these operations are normally very small if you aren’t adding something expensive on top. Measure performance before you cache anything. Caching adds an extra layer of complexity to any solution. Caching menues is normally a bad idea since the menu depends on what user is logged in. Normally you don’t need to cache this and if you do, only cache it for anonymous users.

Best practice tips about caching

Log everything

I would really recommend adding extra logging to all cache logic that specifies whether something is gotten from the cache or not.

Make it possible to get fresh from data source

Include a parameter to your cached method that forces a fresh copy from the data source..

Make it possible to change/disable cache

Preferably as an admin or at least in config files

Think about the first hit

If you want to avoid the first user having a huge load time while the cache is still empty, why not load the data with a scheduled job? You did add that extra parameter for getting fresh from data source right? Then setting up a scheduled job that triggers update will be a piece of cake.

Don't underestimate the complexity of caching

Caching stuff is easy. But it's like a sawed-off shotgun. It's easy to kill someone else by mistake than the one you are aiming at. Give some extra love to choosing the correct cachekeys that includes all parameters and set up the correct cache invalidation. It’s a steady source of errors in solutions that are quite tricky to find later without decent logging.

I’ll dive in to some heavy code later in this blog series but the links above are enough for getting caching to work.The coding part for basic object caching is pretty trivial. I’ll add some examples for the more advanced variants in the next blogs

Feb 01, 2016

Comments

Please login to comment.
Latest blogs
A day in the life of an Optimizely OMVP - Opticon London 2025

This installment of a day in the life of an Optimizely OMVP gives an in-depth coverage of my trip down to London to attend Opticon London 2025 held...

Graham Carr | Oct 2, 2025

Optimizely Web Experimentation Using Real-Time Segments: A Step-by-Step Guide

  Introduction Personalization has become de facto standard for any digital channel to improve the user's engagement KPI’s.  Personalization uses...

Ratish | Oct 1, 2025 |

Trigger DXP Warmup Locally to Catch Bugs & Performance Issues Early

Here’s our documentation on warmup in DXP : 🔗 https://docs.developers.optimizely.com/digital-experience-platform/docs/warming-up-sites What I didn...

dada | Sep 29, 2025

Creating Opal Tools for Stott Robots Handler

This summer, the Netcel Development team and I took part in Optimizely’s Opal Hackathon. The challenge from Optimizely was to extend Opal’s abiliti...

Mark Stott | Sep 28, 2025

Integrating Commerce Search v3 (Vertex AI) with Optimizely Configured Commerce

Introduction This blog provides a technical guide for integrating Commerce Search v3, which leverages Google Cloud's Vertex AI Search, into an...

Vaibhav | Sep 27, 2025

A day in the life of an Optimizely MVP - Opti Graph Extensions add-on v1.0.0 released

I am pleased to announce that the official v1.0.0 of the Opti Graph Extensions add-on has now been released and is generally available. Refer to my...

Graham Carr | Sep 25, 2025