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: Configuring a "region" in the 2nd level cache
PostPosted: Mon Mar 06, 2006 5:34 pm 
Newbie

Joined: Tue Oct 05, 2004 3:00 pm
Posts: 5
It is not clear to me what a region is. I have been unable to find clear documentation on it. One post I read says that a region as defined in a <cache> node is the FullName of the class type. Is this true? I want to set different cache properties on different objects.

In web.config I have:

<configSections>
<section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler,NHibernate.Caches.SysCache" />
</configSections>

<syscache>
<cache region="foo" relativeExpiration="30" priority="3" />
<cache region="bar" staticExpiration="2100-12-31" />
</syscache>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 10:00 am 
Newbie

Joined: Wed Mar 08, 2006 9:36 am
Posts: 4
Look at chapter 14.6 of the documentation. The regions and the way to control them are defined pretty exhaustively there. Here is an excerpt

14.6. The Query Cache

Query result sets may also be cached. This is only useful for queries that are run frequently with the same parameters. To use the query cache you must first enable it by setting the property hibernate.cache.use_query_cache=true. This causes the creation of two cache regions - one holding cached query result sets (net.sf.hibernate.cache.QueryCache), the other holding timestamps of most recent updates to queried tables (net.sf.hibernate.cache.UpdateTimestampsCache). Note that the query cache does not cache the state of any entities in the result set; it caches only identifier values and results of value type. So the query cache is usually used in conjunction with the second-level cache.

Most queries do not benefit from caching, so by default queries are not cached. To enable caching, call Query.setCacheable(true). This call allows the query to look for existing cache results or add its results to the cache when it is executed.

If you require fine-grained control over query cache expiration policies, you may specify a named cache region for a particular query by calling Query.setCacheRegion().

List blogs = sess.createQuery("from Blog blog where blog.blogger = :blogger")
.setEntity("blogger", blogger)
.setMaxResults(15)
.setCacheable(true)
.setCacheRegion("frontpages")
.list();

If the query should force a refresh of its query cache region, you may call Query.setForceCacheRefresh() to true. This is particularly useful in cases where underlying data may have been updated via a seperate process (i.e., not modified through Hibernate) and allows the application to selectively refresh the query cache regions based on its knowledge of those events. This is an alternative to eviction of a query cache region. If you need fine-grained refresh control for many queries, use this function instead of a new region for each query.



Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 12:52 pm 
Newbie

Joined: Tue Oct 05, 2004 3:00 pm
Posts: 5
Thanks for the reply. I had seen that documentation but did not think it applied to my particular problem. I think now it does in fact apply, but it raises some questions in my mind.

Previously, I was trying to enable caching on the fetching of a single object, like so:

(MyClass)Session.Load(typeof(MyClass), id);

So, I know I can swap it for the query below, but does that perform as well? Also, how can I enable a region for Session.Load()? The default "relativeExpiration" that I set when configuring Hibernate seems to work, but I don't know how to set it explictly for type MyClass vs. other types.

(MyClass)Session
.CreateQuery("from MyClass c where c.Id = " + id)
.SetCacheable(true)
.SetCacheRegion("myregion")
.UniqueResult();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 5:34 am 
Newbie

Joined: Tue Apr 25, 2006 2:24 pm
Posts: 2
hi ,please help me
I want monitor NHibernate Cache of a q query?
cfg = new Configuration();
cfg.Configure(HIBERNATE_CFG_XML);
ISessionFactory sessionFactory = cfg.BuildSessionFactory();
aSession = sessionFactory.OpenSession();
q = aSession.CreateQuery("from VocherBDO");
q.SetCacheRegion("my");
q.SetCacheable(true);
IList MyList = q.List();
return MyList;
In Fact i need view about NHibernate caching startegy at Second-level
Cache.


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.