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.

On Wednesday, September 12, 2012 12:30:48 PM UTC-4, Christian I. wrote:
>
> 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>();
>         }
>
>
> <https://lh5.googleusercontent.com/-Ukx4g_2VUfw/UFC4lBPQ16I/AAAAAAAAHGQ/ViHRoh6G_Qw/s1600/12-09-2012+18-20-43.png>
>
>
>

-- 
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/-/OPloANJGgfMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to