Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate L2 Cache configuration in Fluent NHibernate

Tags:

Is ti possible to configure the L2 cache provider in code via FHN?

Adding a line to the following config is what I'm after:

 return Fluently.Configure()                 .Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.FromConnectionStringWithKey("Temp")).ShowSql())                 .Mappings(m => m.FluentMappings.AddFromAssemblyOf<IMap>())                 .ExposeConfiguration(c => { })                 .BuildSessionFactory(); 

Cheers

AWC

like image 335
AwkwardCoder Avatar asked Jan 07 '10 13:01

AwkwardCoder


1 Answers

This is possible from FNH, in the example below see the 'Cache' property:

return Fluently.Configure(fileConfiguration)   .Database(MsSqlConfiguration     .MsSql2005       .ConnectionString(c => c.FromConnectionStringWithKey("Temp"))       .ShowSql()       .Cache(c => c.ProviderClass(typeof(NHibernate.Cache.HashtableCacheProvider).AssemblyQualifiedName)           .UseQueryCache()))     .Mappings(m => m.FluentMappings.AddFromAssemblyOf<IMap>())     .ExposeConfiguration(c => {         c.EventListeners.PostLoadEventListeners = new IPostLoadEventListener[] {new TestPostLoadListener()};       })     .BuildSessionFactory(); 

Cheers

AWC


Note, for Fluent NHibernate >= 3.4.0.0 it appears the configuration is slightly different. Use the nuget package for SysCache from http://nuget.org/packages/NHibernate.Caches.SysCache

return Fluently.Configure(fileConfiguration)   .Database(MsSqlConfiguration     .MsSql2005       .ConnectionString(c => c.FromConnectionStringWithKey("Temp"))       .ShowSql())     .Cache(c => c.ProviderClass<SysCacheProvider>().UseQueryCache())     .Mappings(m => m.FluentMappings.AddFromAssemblyOf<IMap>())     .ExposeConfiguration(c => {         c.EventListeners.PostLoadEventListeners = new IPostLoadEventListener[] {new TestPostLoadListener()};       })     .BuildSessionFactory(); 
like image 51
AwkwardCoder Avatar answered Dec 29 '22 10:12

AwkwardCoder