Skip to content

kowalgta/NHibernate.Caches.Redis

 
 

Repository files navigation

NHibernate.Caches.Redis

This is a Redis based ICacheProvider for NHibernate written in C# using ServiceStack.Redis.

Installation

  1. You can install using NuGet: PM> Install-Package NHibernate.Caches.Redis
  2. Or build/install from source: msbuild .\build\build.proj and then look inside the bin directory.

Usage

Configure NHibernate to use the custom cache provider:

<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache">true</property>
<property name="cache.provider_class">NHibernate.Caches.Redis.RedisCacheProvider, 
    NHibernate.Caches.Redis</property>

Set the IRedisClientsManager (pooled, basic, etc) on the RedisCacheProvider before creating your ISessionFactory:

// Or use your IoC container to wire this up.
var clientManager = new PooledRedisClientManager("localhost:6379");
RedisCacheProvider.SetClientManager(clientManager);

using (var sessionFactory = ...)
{
    // ...
}

clientManager.Dispose();

Configuration

Inside of the app/web.config, a custom configuration section can be added to configure each cache region:

<configSections>
  <section name="nhibernateRedisCache" type="NHibernate.Caches.Redis.RedisCacheProviderSection, NHibernate.Caches.Redis" />
</configSections>

<nhibernateRedisCache>
  <caches>
    <cache region="BlogPost" expiration="900" />
  </caches>
</nhibernateRedisCache>

Changelog

1.1.0

  • Added configuration section for customizing the cache regions.
  • Added sample project.

1.0.0

  • Initial release.

Happy caching!

About

An NHibernate caching provider for Redis.

Resources

Stars

Watchers

Forks

Packages

No packages published