简体   繁体   English

流利的NHibernate Syscache2缓存过期

[英]Fluent NHibernate Syscache2 cache expiration

I've been working on a WCF service that uses fluent and syscache2. 我一直在研究使用fluent和syscache2的WCF服务。 I've pretty much read every article on SO regarding my current dilemma; 关于我目前的困境,我已经阅读了很多关于SO的文章; 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. 我设置的任何值似乎都将被忽略,默认值5分钟用于使缓存过期。

Fluent configuration: 流利的配置:

Note: contextClass is just a descriptor class holding values passed to the configuration. 注意:contextClass只是一个描述符类,其中包含传递给配置的值。

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: 我还设置了app.config文件,如下所示:

<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. 有一个app.config的变体,其中有一个syscache节,该节使用区域,但也不起作用。

Anyone have any suggestions on ideas? 有人对想法有什么建议吗?

Thanks 谢谢

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. 不确定Properties.Add的行为是否不同于您正在使用的SetProperty调用。

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) 看来,如果您使用的是NHibernate的较新版本,则也可以使用NHibernate.Cfg命名空间中的新扩展方法(这将替换整个您的.Cache调用)。

.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. cache.default_expiration或到期时间(Int32):由于NH Contrib 2.1 cache.default_expiration是新的设置名称,应使用它代替到期时间来指定必须使缓存项无效的秒数。 Default value is 300 seconds. 默认值为300秒。 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). 因此,属性名称可能不是您的问题(现在想知道,如果我使用的“ expiration”键可能也专用于内存缓存提供程序,尽管它似乎可以与syscache一起使用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM