Help
Redis Cache Module

Sitefinity uses an in-memory cache service derived from the popular, (in its day) Microsoft Enterprise Library application blocks. The trouble is that if you have a load-balanced environment you save a copy of your cached data on every node. This extension adds a distributed cache option via Redis.

Redis Cache
Module

The package uses the StackExchange.Redis NuGet package and functionality is managed through this implementation.

The module will register its self and provide you a newly named cache option, extending off of the built in ICacheManager.

Requirements

You will first need to ensure you have a Redis server set up and the connection string to it.

Installation

Install the NuGet package to your Sitefinity web application.
Add the modules license to the /App_Data/Sitefinity/ folder.

Configuration

Go to the advanced settings and the PdrRedisCache node.

Redis Settings

When you add the package to your project it will create a configuration section named PdrRedisCache. In here you will need to add the connection string required to connect to your Redis instance. There is also a default cache expire time that will be applied to each item added unless overridden at the time of adding an item to the cache. Keep in mind that because the cache is not associated with your Sitefinity site, the cache does not clear when you restart or recycle the application.

The module will register its self and provide you with a newly named cache option which extends off of the built-in ICacheManager using the name 'RedisCache'.

private static ICacheManager MyRedisCacheManager
{
    get { return SystemManager.GetCacheManager("RedisCache"); }
}

You can then use it just like you do the built-in cache.

MyRedisCacheManager.Add("keya""value a");
var exists = CacheManager.Contains("keya");
var result = (String)CacheManager["keya"];

But First

There is an important point to consider when using Redis and saving data to the store.

Redis saves everything as a RedisValue which is basically a string value. So when you add anything to this cache it must be transformed to a string value. A good option is to convert objects to a JSON string which you can serialise and de-serialize to and from different object types.

Binary data (Byte[]) is also supported with Redis and you can pass it in with this module but this implementation and advice only considers strings.

General Methods

The module supports standard methods as seen above.

Two methods not currently supported are the Flush and Count methods.

It also supports the longer 'Add' method allowing you to define your own cache period.

public void Add(String keyObject valueCacheItemPriority scavengingPriorityICacheItemRefreshAction refreshActionparams ICacheItemExpiration[] expirations)

The 'scavengingPriority' parameter is ignored and the 'expirations' expects an AbsoluteTime item to determine how long this item will stay in the cache.