Domanda

I've been working on a WCF service that uses fluent and syscache2. I've pretty much read every article on SO regarding my current dilemma; I've had no luck.

I am trying to set the expiration time for my second-level cache. Whatever value I set seems to be ignored and the default value of 5 minutes is used to expire the cache.

Fluent configuration:

Note: contextClass is just a descriptor class holding values passed to the configuration.

var cfg = Fluently.Configure()
                .Database(
                    MsSqlConfiguration.MsSql2008                        
                    .ConnectionString(c => c.Is(connectionString))
                    .ShowSql()
                    )
                .Diagnostics(d => d.Enable())                                                             
                .Cache(c => c                                 
                            .UseQueryCache()          
                            .ProviderClass(typeof(NHibernate.Caches.SysCache2.SysCacheProvider).AssemblyQualifiedName))                    
                .Mappings(m => m
                    .FluentMappings
                    .AddFromAssembly(assembly)) 
                .ExposeConfiguration(x =>
                {
                    x.SetProperty(NHibernate.Cfg.Environment.CurrentSessionContextClass, contextClass.Id);
                    x.SetProperty(NHibernate.Cfg.Environment.PrepareSql, contextClass.PrepareSql); //set prepare_sql true/false
                    x.SetProperty(NHibernate.Cfg.Environment.CacheDefaultExpiration, contextClass.ExpireL2Cache); //set default expiration in seconds
                });

I also have the app.config file set up as following:

<configSections>
  <section name="syscache" type="NHibernate.Caches.SysCache2.SysCacheSection, NHibernate.Caches.SysCache2"/>
</configSections>

<syscache>
  <cache expiration="600" priority="5" />
</syscache>

There was a variant of the app.config which had a syscache section that used regions but that didn't work either.

Anyone have any suggestions on ideas?

Thanks

È stato utile?

Soluzione

I've always used this without problems:

.ExposeConfiguration (cfg => {
    cfg.Properties.Add ("expiration", "900");
})

Not sure if Properties.Add behaves any differently than the SetProperty call you're using though.

It seems like if you're using a newer version of NHibernate you can lean on the new extension methods in the NHibernate.Cfg namespace for this as well (this would replace your entire .Cache call in fluent)

.ExposeConfiguration (cfg => {
    cfg.SessionFactory().Caching.Through<SysCacheProvider>().WithDefaultExpiration(900);
})

Doing some reading I found this:

cache.default_expiration or expiration (Int32): since NH Contrib 2.1 cache.default_expiration is the new setting name that should be used instead of expiration to specify number of seconds after which the cache item must be invalidated. Default value is 300 seconds. The old name is still supported for backward compatibility.

So the property name is probably not your issue (wondering now if the "expiration" key that I used was maybe specific to the memcache provider as well, though it seemed to work with syscache).

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