This is my second post regarding Redis. In How To Implement Redis With Episerver Easily .

In my last post, I talked about the benefits of using Redis as a session state provider and a cache manager. To recap the article, Redis provides a persistence cache, you can reboot your Redis server and your users won't lose their session data, this is a big win over technologies like InProc or Memcached.

Using some other technologies when you reboot your server, you lose your cache data. Second, Redis is really really fast, as it uses the NoSQL philosophy, Redis will write data to disk/memory faster than SQL so if you run a load-balanced environment and need to cache data, or persist sessions, it's a good choice.

Redis still provides better benefits than InProc on a single environment so I can't really see a reason why you wouldn't implement it. I also recommend that you implement StackExchange.Redis as your client, as it's free and provides better async support. In the code sample in my last tutorial, I covered the basics of reading/writing data to Redis.

That article only worked with storing strings. In production, I extended this to use Json.Net to serialise/deserialize objects into Redis. That was until I read this article Serialization Performance comparison.

Out of the results, Json.NET is performant, but, Protobuf probably is a little more efficient. If you run a high traffic site where you really care about performance, then this little switch in serialisation/deserialisation methods may provide a quick easy win in the optimization fight. Luckily, there are even two Nuget packages that can extend Redis Stack Exchange Redis, so the amount of code you need to implement this is very small.

In the NuGet Manager, 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 us to save C# objects directly in Redis without you having to write any more code: redis_extensions_nuget_installation Now, In your web.config, add this section:

The matching element somewhere within :

That should have taken you about 3 minutes and all your configuration work is done (assuming you've already installed Redis). The code to cache your data will look like this:

Now you have a simple, performant, cache manager!