-->
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: How use the SessionFactory Level cache
PostPosted: Fri Nov 07, 2003 9:25 am 
Newbie

Joined: Wed Oct 29, 2003 6:15 am
Posts: 7
Hi all,


I am new in Hibernate and I want developed a Web application with Struts abd Hibernate.

I would like to used the SessionFactory level cache.

I put the <jcs-cache> tag in my mapping files and the cache.ccf in my CLASSPATH.

see my cache.ccf

cs.default=DC
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=10000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false
jcs.default.elementattributes.MaxLifeSeconds=3600
jcs.default.elementattributes.IdleTime=1800
jcs.default.elementattributes.IsSpool=true
jcs.default.elementattributes.IsRemote=false
jcs.default.elementattributes.IsLateral=false

# System CACHE REGION
jcs.system.groupIdCache=DC
jcs.system.groupIdCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.system.groupIdCache.cacheattributes.MaxObjects=10000
jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache

#Auxiliary CACHE (disk cache)
jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC.attributes.DiskPath=cache


But I have no performance difference between 2 identical query that return 10000 objects
see result :

Object number 10000.0

Without Cache (y=1)
time (ms) 9132

With Cache (y=2)
time(ms) 8904

see my code :

y = 1 : Whitout cache

y = 2 : With cache

Configuration cfg = new Configuration().addJar(DIRECTORY+JAR_NAME);
SessionFactory sessions = cfg.buildSessionFactory();

Session ses = null;

String query = "my_query";
for(int y = 1 ; y <= 2 ; y++){

ses = sessions.openSession();

List list = ses.find(query);

Iterator iti = list.iterator();

while(iti.hasNext()){

Raw_Value r = (Raw_Value)iti.next();

r.getRaw_value_id();
r.getExpression_level();

}

list = null;
ses.flush();
ses.connection().commit();
ses.close();
}
ses = null;
}

What are my errors ?
How can I configure the SessionFactory level cache correctly?

Thank you for your help

Guillaume


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 3:23 pm 
Newbie

Joined: Wed Aug 27, 2003 2:53 pm
Posts: 14
Location: New Jersey
From the webpage (http://hibernate.bluemars.net/61.html) on Hibernate and JCS:

"Session.find(...) uses Hibernate HQL to execute a query. It is translated into SQL and executed against the database. The cache is never utilised by find(), until Hibernate tries to resolve associations after the initial query. (Of course, find() does add objects to the cache.)"

Your sample code is using Session.find(). You'll never see performance improvements resulting from caching in this case. You need to use Session.load() to see the benefits of caching.

Sarah

[/url]


Top
 Profile  
 
 Post subject: 2.0.3 seemed to cache find() results
PostPosted: Fri Nov 14, 2003 4:01 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
In Hibernate 2.0.3 (I just switched to the 2.1beta6), I found my session.find() results were being cached. I did the same queries a few time but, in between, I updated the MySQL table manually. Every time I went back to that web page, the find() returned the same cached results, not the new information from the database. Adding
'Transaction tx = session.beginTransaction()' forced it to go to the database every time and pull the current results. Odd.

The funny thing was, I didn't have any cache settings in my hibernate.cfg.xml file. I only had a transaction.factory_class using the JDBC factory.

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 7:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
In Hibernate 2.0.3 (I just switched to the 2.1beta6), I found my session.find() results were being cached. I did the same queries a few time but, in between, I updated the MySQL table manually. Every time I went back to that web page, the find() returned the same cached results, not the new information from the database. Adding
'Transaction tx = session.beginTransaction()' forced it to go to the database every time and pull the current results. Odd.


You are mistaken.

(Unless your database is in serializable isolation mode or something.)

Hibernate 2.1 adds a query cache, but this is disabled by default.


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.