-->
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.  [ 10 posts ] 
Author Message
 Post subject: Second Level Caching
PostPosted: Thu Jul 05, 2007 4:05 pm 
Newbie

Joined: Tue Jul 03, 2007 11:50 am
Posts: 9
Using nHibernate version:1.2 trying to implement caching of frequently used Reference data for a Winforms app using syscache2. Is this possible? The previous postings on the forums and the help documentation is ambiguos. One gets the impression that collections cannot be cached.

NHibernate config is
configuration.SetProperty"hibernate.cache.provider_class", "NHibernate.Caches.SysCache2.SysCacheProvider, NHibernate.Caches.SysCache2");
configuration.SetProperty("hibernate.cache.use_second_level_cache", "true");
configuration.SetProperty("hibernate.cache.use_query_cache", "false");

Config file is as follows
<section name="syscache2" type="NHibernate.Caches.SysCache2.SysCacheSection, NHibernate.Caches.SysCache2"/>
</configSections>

<syscache2>
<cacheRegion name="PatientStatus">
<dependencies>
<tables>
<add name="price"
databaseEntryName="Paceart"
tableName="Paceart.Patient_Status" />
</tables>
</dependencies>
</cacheRegion>
</syscache2>
What should be the value of name in the "<tables><add name=" be ??

Mapping File is
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="paceart" default-lazy="false">
<class name="Paceart.Domain.Lookups.PatientStatus, Paceart.Domain" table="PATIENT_STATUS">
<cache usage="read-write" region="PatientStatus" />
<id name="Key" type="Guid" column="PatientStatusKey">
<generator class="assigned" />
</id>
<version name="Version" column="Version" type="Int32" unsaved-value="null" />
<property name="Code" column="Code" type="String" />
<property name="Description" column="Description" type="String" />
<property name="SortOrder" column="SortOrder" type="Int32" />
<property name="LongDescription" column="LongDescription" type="String" />
</class>
</hibernate-mapping>

The Select for the Patient Statuses shows up in the SQL Profiler everytime it is requested. Wanted to know if it is even possible to implement reference data caching using nHibernate. If yes what am I missing.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 4:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Caching of queries has to be explicitly enabled with a call to SetCacheable() like this:

Code:
session.CreateQuery("from Whatever")
    .SetCacheable(true)
    .List();


It is not dependent on the cache provider. Give that a try and let us know how it goes.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 4:24 pm 
Newbie

Joined: Tue Jul 03, 2007 11:50 am
Posts: 9
I do not want to cache the queries. I want to cache the actual collections/instances of objects.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 4:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
I believe we are talking about the same thing... just different terminologies. Have a look at the second-last post of this thread to see if it helps you:

http://forum.hibernate.org/viewtopic.php?t=976960

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 4:39 pm 
Newbie

Joined: Tue Jul 03, 2007 11:50 am
Posts: 9
How can I do this
session.CreateQuery("from Whatever").SetCacheable(true).List();
at the SessionFactory level as oppossed to the individual session level?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 4:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
I don't believe it is possible to enable query caching by default for all queries... if that is what you meant. I am not too sure though. Maybe have a look at the API doc for ISessionFactory.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 5:04 pm 
Newbie

Joined: Tue Jul 03, 2007 11:50 am
Posts: 9
When I try to do what you suggested it infact added an extra select for each request. The first time I requested the list it selected it twice from the database. The same query shows up twice in the SQL profiler. On the second go around instead of grabbing the stuff from the cache(ideally) it gain fires the same select twice.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 5:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
I just notice in your original post, you have
Code:
configuration.SetProperty("hibernate.cache.use_query_cache", "false");

You need to set that to true as in
Code:
configuration.SetProperty("hibernate.cache.use_query_cache", "true");

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 10:51 am 
Newbie

Joined: Tue Jul 03, 2007 11:50 am
Posts: 9
I was able to eliminate the extra select for each request of the collection. But still it goes to the database for the second request.
I have a very basic question, Is it even possible to cache collections in the second level cache?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 11:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
May be I am at the end of my helpfulness here... if I had even been helpful at all. Like many apps out there, my app have a lot of reference data (like a list of countries, for example). I have used the second level cache successfully with a method like this:

Code:
public IList<Country> GetCountries() {
    return session.CreateQuery("from Country")
        .SetCacheable(true)
        .List<Country>();
}


The cache provider I use is memcache. Maybe your problem is related to Syscache2? The final suggestion I have would be to isolate the problem; that is, maybe switch to a different cache provider to make sure your problem is not specific to Syscache2 and go from there.

Perhaps someone else could weight in here. Good luck.

_________________
Karl Chu


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