Yes, I realized I had that in a different code branch right around the time 
you answered. Too many branches in flight at the same time. :-)

Anyway, thanks. That's definitely what was missing.


On Thursday, August 8, 2019 at 2:23:32 PM UTC-4, Gunnar Liljas wrote:
>
> You must specify that you want the query to be cached/use the cache.
>
> session.Query<T>().WithOptions(x=>x.SetCacheable(true)).FirstOrDefault(e 
> => e.Id == id) 
>
> Den tors 8 aug. 2019 kl 18:55 skrev Eric Rizzo <eric...@gmail.com 
> <javascript:>>:
>
>> I'm trying to configure the Level 2 entity and query caches for an 
>> existing working application, but they're not being used at all from what I 
>> can tell.
>> I've set the following config in my web.config:
>>
>> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
>>   <session-factory>
>>     <property name="dialect">NHibernate.Dialect.MsSql2012Dialect</
>> property>
>>     <property name="adonet.batch_size">50</property>
>>     <property name="hbm2ddl.keywords">auto-quote</property>
>>     <property name="max_fetch_depth">3</property>
>>     <property name="cache.use_second_level_cache">true</property>
>>     <property name="cache.provider_class"
>> >NHibernate.Caches.RtMemoryCache.RtMemoryCacheProvider,NHibernate.Caches.RtMemoryCache</
>> property>
>>     <property name="cache.use_query_cache">true</property>
>>   </session-factory>
>> </hibernate-configuration>
>>
>> <!-- Hibernate Level2 cache-->
>> <rtmemorycache>
>>  <cache region="MyEntity" expiration="28800"/> <!-- expiration is in 
>> seconds -->
>> </rtmemorycache>
>>
>>
>> In my entity mapping I have this:
>>
>> <cache usage="read-write" region="MyEntity" />
>>
>>
>> We use the session-per-request pattern, and are using explicit 
>> transactions:
>>
>> ISession session = factory.OpenSession();
>> CurrentSessionContext.Bind(session);
>> session.BeginTransaction();
>>
>> I've stepped through in the debugger and I see the config properties and 
>> the cache provider being created.
>>
>>
>> But when I repeatedly run the same query (using Swagger or Postman) I see 
>> the SQL being logged every time and NHibernate Profiler tells me it is 
>> indeed querying the database every time.
>>
>> Here's the query I'm using as my test:
>>
>> session.Query<T>().FirstOrDefault(e => e.Id == id)
>>
>>
>> Here is what Profiler is telling me about cache usage:
>>
>> [image: NHPRofiler 1.png]
>>
>>
>> Any ideas how to troubleshoot the non-use of the caches are welcome. I'm 
>> really stumped.
>>
>>
>> Thanks in advance,
>>
>> Eric
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "nhusers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to nhu...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/nhusers/43bde487-c9e0-481b-9a36-43a141c4f2ec%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/nhusers/43bde487-c9e0-481b-9a36-43a141c4f2ec%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nhusers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nhusers/63619cb2-5343-4694-96e8-29d2535cd70f%40googlegroups.com.

Reply via email to