Second level cache, normal behavior ?

43 views
Skip to first unread message

Christian I.

unread,
Sep 12, 2012, 12:30:48 PM9/12/12
to nhu...@googlegroups.com
Hello,

I join a screenshot. I have a Customer table and a Risk (with 4 rows) table, each customer is associate to a risk.

1. First transaction, I get the list of customer 
2. I select one, to see detail, I get the list of risk to display in a dropdown
3. Thirs transaction, back to the list of customer
4. I select an another one, now I see Nhibernate use the cache. The question is : is it normal I have 4 queries to the risk table. On the fourth NHProfiler warn me (N+1)

I did something wrong ?

Thanks,

Implementation I use :

1. In the web.config, in the configSections : <section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler, NHibernate.Caches.SysCache" />

2.   <syscache>
    <cache region="SomeCustomNameRegion" expiration="86400" priority="5" />
  </syscache>

3. The query :
    public IList<Risk> GetListRisk()
        {
            return Session.QueryOver<Risk>()
                .Cacheable()
                .CacheMode(CacheMode.Normal)
                .CacheRegion("SomeCustomNameRegion")
                .List<Risk>();
        }




Oskar Berggren

unread,
Sep 12, 2012, 12:43:38 PM9/12/12
to nhu...@googlegroups.com
Missing batch-size on the Risk mapping?

/Oskar


2012/9/12 Christian I. <christi...@gmail.com>


--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/4hi3SIXFwcIJ.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Jason Meckley

unread,
Sep 12, 2012, 1:44:47 PM9/12/12
to nhu...@googlegroups.com
2nde level cache can be a bit tricky to setup. not only do you need to enable 2nd level, you then need to configure the 2nd level cache provider and configure the entities involved with the 2nd level cache. the entity itself is not cached, only the values of the entity. relationships are cached by the ID only. therefore if you cache the root, but not the related entities the related entities are loaded using select n+1. in this scenario both the root entity, & the child entities need to be marked as cache-able.

then there is the query cache, which again is another layer of configuration.

also, all queries (both reads & writes) must be wrapped within a transaction. 2nd level cache depends on the transaction to manage when cached values become stale.
Reply all
Reply to author
Forward
0 new messages