aspose file tools*
The moose likes Object Relational Mapping and the fly likes hibernate cache mode - put vs refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate cache mode - put vs refresh" Watch "hibernate cache mode - put vs refresh" New topic
Author

hibernate cache mode - put vs refresh

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

The JavaDoc for CacheMode.PUT and CacheMode.REFRESH have the same first sentence "The session will never read items from the cache, but will add items to the cache as it reads them from the database."

REFRESH adds "In this mode, the effect of hibernate.cache.use_minimal_puts is bypassed, in order to force a cache refresh ". Presumably this sentence is the difference between the two.

I'm not sure I understand the difference. Is it that REFRESH forces a cache update and PUT only does it sometimes? (I do have a book, but it describes it in essentially the same way and I don't follow that either.)

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Yes.



Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

On a serious note.

I think it makes a little more sense in thinking in terms of using CacheMode on a query by query use case. In some cases you don't need to check the cache for data, you might be just adding stuff to the cache. Like lets say at startup we load the 50 states into our cache. Either PUT or REFRESH will load all 50 states into the cache. We don't need to read from the cache here, we are just loading into cache for our app to use later. In those later queries to get the states to present to the user, we don't need either PUT or REFRESH because we know the entire 50 states are already in the cache.

OK, now lets say we have some task that runs once a day, and it is to update some data that we put into the cache, that changes a little bit every 24 hours, and now we want to update that data that is now stale in the cache. Do we want to flush and refresh the entire cache region for this data or just update the things that changed. This I believe is the distinction between PUT and REFRESH. Put will just update the things that are changed, and refresh will clear out the entire cache region and reload everything. In the reload/REFRESH scenario is probably a bit faster if there is a lot of difference, and therefore doesn't have code that compares the new loaded data versus what is in the cache, which I think PUT would do.

Sounds like it now makes sense to me, but I can't guarantee it's accuracy. ;)

Mark
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Makes sense. Thanks Mark.
Brendon Woodford
Ranch Hand

Joined: Jan 22, 2010
Posts: 53
hi all,
As Mark has written
I think it makes a little more sense in thinking in terms of using CacheMode on a query by query use case. In some cases you don't need to check the cache for data, you might be just adding stuff to the cache.

This does make sense.
But my question is if the CacheMode.GET signifies :The session may read items from the cache, but will not add items, except to invalidate items when updates occur ;how on earth is it possible to have the objects in the cache in the first place if the session does not allow the data to be added to the Second level cache?

The same question pertains to CacheMode.PUT : The session will never read items from the cache, but will add items to the cache as it reads them from the database.. If the session does not allow items to be read from the cache then why would anybody read them to the second level cache in the first place?
Your response is appreciated.
Thank you all
Brendon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate cache mode - put vs refresh