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
I've always used this without problems:
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)
Doing some reading I found this:
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).