Nhibernate ICriteria可设置缓存到期时间
我想知道如何让NHibernate在指定的时间内在2级缓存中存储我的查询 我只看到实体缓存Nhibernate ICriteria可设置缓存到期时间,nhibernate,caching,criteria,Nhibernate,Caching,Criteria,我想知道如何让NHibernate在指定的时间内在2级缓存中存储我的查询 我只看到实体缓存 感谢您的回复。默认情况下,查询缓存未启用。要在hibernate.cfg.xml中启用它,请执行以下操作: <add key="hibernate.cache.use_query_cache" value="true" /> 您应该为查询指定缓存区域。如果未指定,则区域将为“NHibernate.Cache.StandardQueryCache” Session.CreateCriter
感谢您的回复。默认情况下,查询缓存未启用。要在hibernate.cfg.xml中启用它,请执行以下操作:
<add key="hibernate.cache.use_query_cache" value="true" />
您应该为查询指定缓存区域。如果未指定,则区域将为“NHibernate.Cache.StandardQueryCache”
Session.CreateCriteria()
.SetCacheRegion(“用户查询”)
.List();
对于syscache,缓存区域在app.config中配置:
<configuration>
<configSections>
<section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler,NHibernate.Caches.SysCache" />
</configSections>
<syscache>
<cache region="User" expiration="300" priority="3" />
<cache region="UserQuery" expiration="60" priority="3" />
</syscache>
</configuration>
<configuration>
<configSections>
<section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler,NHibernate.Caches.SysCache" />
</configSections>
<syscache>
<cache region="User" expiration="300" priority="3" />
<cache region="UserQuery" expiration="60" priority="3" />
</syscache>
</configuration>