How to set up NHibernate second level cache in NHibernate> = 3.2?

Before upgrading to NHibernate 3.2, I used the following code for Fluent NHibernate:

OracleClientConfiguration configurer = (OracleClientConfiguration.Oracle10.ShowSql().ConnectionString(c =>
                         c.FromConnectionStringWithKey(ConnectionString.Development))
                         .DefaultSchema("MySchema")
                         .UseReflectionOptimizer()
          /* Here --> */ .Cache(c => 
                                 c.ProviderClass<SysCacheProvider>()
                                 .UseQueryCache()));

      

However, the extension method is .Cache()

no longer found in NHibernate 3.2.

How do I set up a cache provider?

Edit: I've also tried:

        .ExposeConfiguration(configuration =>
        {
            configuration.SetProperty(Environment.UseQueryCache, "true");
            configuration.SetProperty(Environment.CacheProvider, "NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache2");
        });

      

+3


source to share


2 answers


This is an excerpt from my configuration using the SysCache provider.



var configuration = new Configuration()
    .Cache(x => x.UseQueryCache = true)
configuration.SessionFactory()
    .Caching.Through<SysCacheProvider>().WithDefaultExpiration(60)

      

+6


source


see http://www.markhneedham.com/blog/2010/06/16/fluent-nhibernate-and-the-2nd-level-cache/ & amp; https://web.archive.org/web/20110514214657/http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/11/09/first-and-second-level-caching-in-nhibernate.aspx

A common mistake (This happened to me too!) Is to forget to commit or omit a transaction when adding or changing an object / aggregate to the database. If we now access the entity / aggregate from another session, then the second-level cache will not be ready to provide us with cached instances and NHibernate (unexpected round trip of the database).



I have the same problem and have searched for it many times, I finally saw this. The bad news is I tried to use trasaction and still couldn't open the L2 cache!

0


source







All Articles