-->
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.  [ 2 posts ] 
Author Message
 Post subject: Second-level cache
PostPosted: Wed Jun 09, 2004 7:58 am 
Newbie

Joined: Wed May 26, 2004 4:16 am
Posts: 7
Hi,

I have a goal to minimize network and database overhead. In order to do so, I load all often-used objects into second-level cache (EHCache) at system startup. Although EHCache log says all requests hit cache, I still see in the output a lot of SQL , loading those "cached" objects, and see high traffic on the net.

What's wrong and how can I fix it?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 09, 2004 8:35 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
I have some experements with second level cache, and as I got for better performance you should configure cache for all child objects of your parent.

That is for the following object model
Code:
Parent -<> ChildA
    |-<> ChildB
              |-<> ChildC


you should configure read-only/nonstrict-read-write cache for Parent, ChildA, ChildB and ChildC (if you need all your object be in the memory else use read-write cahce)

Code:
<hibernate-mapping>
   <class name="full.class.name.Parent" table="`Parent`" batch-size="10"
      mutable="false" dynamic-update="false" dynamic-insert="false">

      <cache usage="read-only"/>
...


and for cache tuning, configure ehcache regions in the ehcache.xml for each of those classes, be aware of eternal="true" in that example:

Code:
<ehcache>
   <diskStore path="java.io.tmpdir"/>
   <defaultCache
      maxElementsInMemory="10000"
      eternal="false"
      timeToIdleSeconds="120"
      timeToLiveSeconds="120"
      overflowToDisk="false"
      />
    <cache name="full.class.name.Parent"
      maxElementsInMemory="10000"
      eternal="true"
      timeToIdleSeconds="0"
      timeToLiveSeconds="0"
      overflowToDisk="false"
      />
    <cache name="full.class.name.ChildB"
      maxElementsInMemory="10000"
      eternal="true"
      timeToIdleSeconds="0"
      timeToLiveSeconds="0"
      overflowToDisk="false"
      />
...
</ehcache>


For all collections in your classes enable cache too,
Code:
<bag...>
   <cache .../>
</bag>


In addition, use QueryCache:
in ehcache.xml
Code:
<cache name="net.sf.hibernate.cache.QueryCache"
      maxElementsInMemory="10000"
      eternal="false"
      timeToIdleSeconds="300"
      timeToLiveSeconds="600"
      overflowToDisk="false"
      />


in java code:
Code:
session.createQuery(queryStr).setCacheable(true);


And I think you already read the following docs:
http://www.hibernate.org/158.html
http://ehcache.sourceforge.net/

Also wait for chapter 5 of http://www.manning.com/catalog/view.php?book=bauer, Christian Bauer said there will be helpfull examples and best practicces
http://forum.hibernate.org/viewtopic.php?t=930848

read the thread
http://forum.hibernate.org/viewtopic.php?t=931007

--
Regards,
Leonid


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