Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
649 views
in Technique[技术] by (71.8m points)

caching - NHibernate L2 Cache configuration in Fluent NHibernate

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...