-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Second level cache not recommended?
PostPosted: Fri Feb 24, 2012 4:24 am 
Newbie

Joined: Fri Feb 24, 2012 12:40 am
Posts: 2
I've used Kodo in the past for persistence and it's second level cache increased performance significantly. I'm now considering moving to Hibernate and have been looking at the documentation at the Hibernate second level cache and a have found the wording puzzling in section 6.2.1 (Version 4 docs):

"By default, entities are not part of the second-level cache, and their use is not recommended. If you absolutely must use entities, set the shared-cache-mode element in persistence.xml, or use property javax.persistence.sharedCache.mode in your configuration."

Looking at older versions of documentation from 3.x, I don't see this kind of statement that recommends against using entities in the second level cache. I would have presumed that having entities in the second level cache is how you'd get good performance from it. Anyone know why its use is now not recommended? I was thinking of using ehcache for the second level cache which seemed to have been the default provider from old articles I've read.


Top
 Profile  
 
 Post subject: Re: Second level cache not recommended?
PostPosted: Fri Feb 24, 2012 4:52 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi hjo,


Quote:
By default, entities are not part of the second-level cache, and their use is not recommended.


I think this sentence is expressed unhappily.
What's this sentence intends to say in my opinion is:

It it not recommended to set entity caching javax.persistence.sharedCache.mode to ALL or to DISABLE_SELECTIVE
You should indeed use caching javax.persistence.sharedCache.ENABLE_SELECTIVE (=default)
and explicitly mark determinate entity classes as cachable. This is the default and recommended value.

There's also the note:
Quote:
When possible, define the cache concurrency strategy per entity rather than globally. Use the @org.hibernate.annotations.Cache annotation.


I guess the motivations are:
-enabling sharedCache.mode to ALL may cause the 2L-Cache requiring to much ressources (or the 2L-Cache becomes rather ineffective due to many evictions and re-puts)
-with selective enabling you can use concurrency strategies which are more appropriate for the given classes.
For example is the content of a entity class is static, you should use the read-only concurrency strategy for it.

I use Hibernate since more than a year sucessfully with 2L-cache caching entities as well as collections and queries.
So far I never encountered problems and the performance gain was clearly measureable.


Top
 Profile  
 
 Post subject: Re: Second level cache not recommended?
PostPosted: Fri Feb 24, 2012 8:13 am 
Newbie

Joined: Fri Feb 24, 2012 12:40 am
Posts: 2
Thanks - appreciate the useful info you've provided!


Top
 Profile  
 
 Post subject: Re: Second level cache not recommended?
PostPosted: Sat Feb 25, 2012 12:41 pm 
Newbie

Joined: Fri Feb 17, 2012 8:20 am
Posts: 18
Second level cache is always good choice...!!!!

How To Enable Second Level Caching In Hibernate

Hibernate Second Level Cache Example


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.