-->
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.  [ 7 posts ] 
Author Message
 Post subject: Second-Level Cache Usage
PostPosted: Wed Apr 26, 2006 10:30 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi,

I want to enable second-level caching for my application and it appears very straightforward to configure in NHibernate. I am not sure about the different values for the usage property of the cache element.

Nearly all of my domain objects can be read and updated so does that mean that I should always use "read-write"? What are the actual differences between each of the settings and what impact will they have on the application?

Also, I am a little unclear as to how the different cache regions work with Session.Get() and Session.Load(). When using the ICriteria, you can set the cache region to use but I am not seeing how this is possible with the Get or Load so which of the cache regions will the object be added to?

Thanks,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 8:38 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
partial answers...

there are three settings in NH:

nonstrict-read-write - no guarantee of consistency between cache and db. used if data doesn't change much (like days or weeks) and you can afford a small amount of risk of data inconsistency. impact: improves performance by reducing the database access overhead for objects that don't change often if used properly.

read-write - read committed isulation, non clustered envirnoments. used when the state of the object changes frequently and you need to make sure the cache is consistent with the db.mpact: improves performance by reducing the database access overhead but not as much as nonstrict. still makes a lot of sense to employ caching. i use this for Member (Person) objects.

read-only - used only for data that never changes. i use these for "month" and "country" objects as an example. They just don't change at all really and if they do, there is usually a new app deployed which means a restart. impact: all but eliminates the database access overhead for these types of objects.


session.get and session.load add their objects to the first-level cache. you cannot change that as far as i know.

hth,

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 9:01 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Thanks Devon, that helps a lot. Is there a doc somewhere that explains the logic behind each of these settings?

In relation to the Get and Load, are you saying that these objects do not get added to the second-level cache? I do not want to prevent them from being added to the first-level cache but I assumed that they would also go into the second-level cache and wanted to know how to control which cache region they were added to as I was intending on having a couple of different regions.

Cheers,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 9:46 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
cache info from the docs:

http://www.hibernate.org/hib_docs/nhibe ... he-mapping

also, there is a good description in the "Hibernate in Action" book. It is java-based but much of the information is invaluable for any Hibernate/NHibernate work.

You can configure the object for storage in the second-level cache using the <cache usage=""> property in the mapping file. Otherwise it simply gets stored in the first-level cache.

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 10:13 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Yeah...I have already added the <cache> element to the entities but there doesn't seem to be any way to control which cache region they go into in the same way that you can for queries. I assume that they therefore go into their own cache region but it isn't clear if that is really the case. If they do go into their own region, how do you control the cache expiration?

BTW, I am using NHibernate.Caches.SysCache.

Thanks for your help.

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 10:36 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
oh, (doh!) now i see what you're asking. sorry to be so dense. each object has its own region, and each collection has its own region. (cache:classname or class:collectionName.) configuring them is dependent upon the cache provider. reffering to this documentation:

http://www.hibernate.org/hib_docs/nhibe ... s.SysCache

you would need to configure for each object and/or collection.

Code:
<cache region="my.class.hierarchy.class" expiration="300" priority="3" />


hth,

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 11:25 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Aha! That's the ticket. Couldn't find this hidden gem in the doco's but maybe I'm just not looking in the right place!

Thanks a lot for all your help...I think we're done now :-)

Jason


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.