nhibernatefluent-nhibernatenhibernate-caches

How to configure NHibernate's 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 .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");
        });

Solution

  • 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)