3

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");
        });
rebelliard
  • 9,592
  • 6
  • 47
  • 80

2 Answers2

6

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)
Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154
  • 1
    This apparently worked, however, NHibernate Profiler says "Second Level Cache Put Count: N (say, 44)", while the "Cache Hit Count" says 0. Do you have any idea why caching is not working? – rebelliard Apr 03 '12 at 15:36
  • @rebelliard - did you get any further with discovering why it wasn't working? It doesn't seem to work for me either... – Chris Haines May 30 '13 at 15:55
  • @Hainesy I never did, actually. In fact, I just checked and I rollbacked my project to NH 3.1.x (+ Fluent Hibernate + Sharp Architecture) because of this. I have since moved out of working mainly on C#, so I'm not sure what has changed in this year regarding this issue... – rebelliard May 30 '13 at 19:46
1

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!

tinonetic
  • 7,751
  • 11
  • 54
  • 79
shamork
  • 11
  • 2