-->
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.  [ 1 post ] 
Author Message
 Post subject: What second level cache is useful for?
PostPosted: Fri Aug 14, 2009 12:19 pm 
Newbie

Joined: Mon Oct 20, 2008 11:37 am
Posts: 7
Now, when I know how to use the Hibernate Second Level Cache, I am trying to figure out why or when I have to use it in my web application. When I retrieve an object from a database, it resides in memory until there is at least one active reference to it around. If I want it to remain in memory between requests (when all local references disappear), I can add it to the HttpSession instance. In this case the life span of an object in memory will be same as the lifespan of the session instance. If I prefer to use the Hibernate Second Level Cache I will not put an object into a session, but instead will place it into the cache. But I still need its Id to be able to find it in the cache. So instead of using httpsession.setAttribute(param_name,object)/httpsession.getAttribute(param_name) I will using httpsession.setAttribute(param_name,object_id)/httpsession.getAttribute(param_name) plus commands to store and retrieve the object from the cache.
So what is the benefit?
I see only two potential benefits:
1. The Hibernate Second Level Cache is more compact storage because it stores only parameters, but not a class as a whole.
Does this overweight an addition complexity?
2.The Hibernate Second Level Cache allows to use a disk as a storage. Using a disk instead of memory slows down access. It probably still will be faster then just reading from a database, but much slower then access to an object in memory.
So, what could be a compelling case for use the Hibernate Second Level Cache instead of HttpSession except for the case of extremely big objects or extremely big collections of objects?

Lev Tannen


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

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.