Yes, we can set the validity period of the cache through the region. Adjust the query as follows:
criteria.SetCacheable(true) .SetCacheMode(CacheMode.Normal) .SetCacheRegion("LongTerm");
And add a similar configuration to the web.config file
<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>
EDIT : I just add this link Cache class that is not used when retrieving an object by criteria Of course, I mean the SQL Query cache. In a related answer, I explain that the topic
Just for clarity. The NHibernate "session-factory" configuration should contain:
<property name="cache.use_query_cache">true</property>
This switch will make the query cache work. More details: http://nhibernate.info/doc/nh/en/index.html#performance-querycache
source share