C# RedisCacheDependency Class

If you need a Fast and out of process Redis Server based Cache Dependency in your ASP.Net application, you can use my RedisCacheDependency class

class RedisCacheDependency : CacheDependency
{
  public RedisCacheDependency(string key) : base()
  {
    // http://redis.io/topics/notifications
    // https://github.com/StackExchange/StackExchange.Redis
    // http://habrahabr.ru/post/240269/
    RedisClient.GetSubscriber().Subscribe(key, (c, v) =>
    {
        this.NotifyDependencyChanged(new object(), EventArgs.Empty);
    });
  }
}

All you need is to define RedisClient some where in your Global.asax Application_Start like

RedisClient = ConnectionMultiplexer.Connect(ConfigurationManager.AppSettings["RedisConfigurationString"]);

Leave a Reply