In this tutorial, you will learn how to improve your page speed by using a Redis to cache Episerver CMS objects. In this post, I assume you know a little about Redis and how to integrate it with Episerver CMS. If Redis is new to you, I suggest you read How To Implement Redis With Episerver Easily first. In this article, I discuss the benefits of using Redis as a session state provider and a cache manager within an Episerver CMS powered website.

Redis provides a persistence caching player. If you use Redis to store user sessions data and reboot your Redis server, that session data will not be lost. This is a big win over technologies like InProc or Memcached. Reboot your server using these technologies would result in lost cache data. Redis is also really really fast 🏃🏃🏃 A Redis server can write data to disk/memory faster than a comparable SQL query. If you run your website in a load-balanced environment and need to cache data, or persist sessions, Redis is a good choice. Redis provides better benefits than its competitors, so I can't really see a reason why you wouldn't implement it.

Out-of-the-box, Redis will only store key/value data as strings. If you want to store C# objects in Redis then you will need to write some additional code. You could use a framework like Json.Net to serialise/deserialize objects into Redis, however, there is a more performant way. A speed comparison was made on how to store objects in Redis (see here. The experiment found that Json.NET is performant, but, Protobuf is more efficient.

If you run a high traffic site where you really care about performance, this little switch in serialisation/deserialisation technologies may provide a win to boost your site's performance. Assuming you are using StackExchange to store your data. There are even two Nuget packages that can extend Stack Exchange Redis to work with Protobuf, so the amount of code you need to implement this is very small.

To get going, install StackExchange.Redis.Extensions.Core and StackExchange.Redis.Extensions.Protobuf. These packages will provide a Protobuf Serializer and a set of extension methods that will allow you to serialise and deserialise objects. You will be able to store C# objects directly in Redis without you having to write any extra code, nice 💗💗💗.


After installing both packages, in your web.config, add this section:

Add this section somewhere within the configuration section :

This process should have taken you about 5 minutes, the good news is that all of your configuration work is now complete. The code to cache an object is shown below:

Now you have a simple, performant, cache manager! Happy Coding 🤘