NHibernate查询缓存过期

时间:2012-10-30 17:29:52

标签: nhibernate query-cache

是否可以配置NHibernate查询缓存的到期时间?

对于二级缓存,我可以从nhibernate.cfg.xml执行此操作,但我无法找到SQL查询缓存的方法。

修改

ICriteria query = CreateCriteria()
                  .Add(Expression.Eq("Email", identifiant))
                  .SetCacheable(true)
                  .SetCacheRegion("X");



 <syscache>
    <cache region="X" expiration="10" priority="1" />
  </syscache>

1 个答案:

答案 0 :(得分:6)

是的,我们可以通过区域设置缓存过期。像这样调整查询:

criteria.SetCacheable(true)
    .SetCacheMode(CacheMode.Normal)
    .SetCacheRegion("LongTerm");

并将类似配置放入web.config文件

<configSections>
    <section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler, NHibernate.Caches.SysCache" requirePermission="false" />
</configSections>
<syscache>
    <cache region="LongTerm" expiration="180" priority="5" />
    <cache region="ShortTerm" expiration="60" priority="3" />
</syscache>

编辑:我只是添加此链接Class-cache not used when getting entity by criteria 确定 SQL查询缓存的含义。在链接的答案中,我正在解释该主题

为了清楚起见。 NHibernate“session-factory”的配置必须包含:

<property name="cache.use_query_cache">true</property>

此开关将使查询缓存工作。更多详情:http://nhibernate.info/doc/nh/en/index.html#performance-querycache