Domanda

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 .Cache() extension method is no longer found in NHibernate 3.2.

How would do I setup my cache provider?

Edit: I also tried:

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

Soluzione

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)

Altri suggerimenti

see http://www.markhneedham.com/blog/2010/06/16/fluent-nhibernate-and-the-2nd-level-cache/ & 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 error (It happened to me as well!) is to forget to commit or omit a transaction when adding or changing an entity/aggregate to the database. If we now access the entity/aggregate from another session then the 2nd level cache will not be prepared to provide us the cached instances and NHibernate makes an (unexpected round trip to the database).

I have the same problem,and googled for it many times,at last i saw this. The bad news is, I tried using trasaction and still failed with opening 2nd level cache!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top