This is a Redis based ICacheProvider for NHibernate written in C# using StackExchange.Redis.
- NuGet
- git submodule add https://github.com/wallymathieu/NHibernate.Caches.StackExchange.Redis.git
- Fork and make a submodule (you might want a different version of StackExchange.Redis)
- Copy the relevant code (it's MIT)
- Private nuget stream (if you are building using appveyor it's quite simple)
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>
Wire up configuration section in app or web config:
<configSections>
<section name="rediscache" type="NHibernate.Caches.StackExchange.Redis.SectionHandler,NHibernate.Caches.StackExchange.Redis" />
And then add the settings:
<rediscache>
<cache region="foo_bar" expiration="999" priority="4" />
</rediscache>
To set the connection settings using c#:
RedisCacheProvider.ConnectionSettings = new RedisCacheConnection("localhost", 6379) { { "allowAdmin", "true" }, { "abortConnect", "false" } };
Happy caching!