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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nhusers/43bde487-c9e0-481b-9a36-43a141c4f2ec%40googlegroups.com.