• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Query Cache

 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I try to setup Hibernate Query Cache, I am using ehcache.

It works in the beginning (i.e. if i execute the same query multiple times,
it does not send the sql commands to mysql everytime).

however, after about 1 minutes, the cache seems expire (i.e. I see hibernate executes sql commmands to the database.


I have the following configuration in my ehcache.xml file. So the query cache should last 2 hours (7200 seconds), I don't understand why my query cache expires so soon.

Thank you for any help.

<defaultCache maxElementsInMemory="10000" eternal="false" overflowToDisk="true" timeToIdleSeconds="7200" timeToLiveSeconds="7200" diskPersistent="false" diskExpiryThreadIntervalSeconds="7200"/>
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- show the code where you create the query
- are there more different queries than the cache size ?

pascal
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we are talking about the Query Cache, do the parameters of your query change? This will mean the cache needs rebuilt.

However, you mention ehcache, which suggests this might be about Second Level caching, which is nothing to do with Query Caching. In which case, you might want to check that your cache has not become full.
 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help.



No, I am pretty sure that the query only return 1 result.
And I am sure that the query parameters are the same everything i execute the query because I just reloading the same page again and again (which trigger the query with parameters).

I appreciate if anyone can give me some ideas to my problem.
 
kri shan
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to set the hibernate.cache.use_query_cache property in the hibernate.cfg.xml file to true, as follows:

<property name="hibernate.cache.use_query_cache">true</property>

Then, you use the setCacheable() method.

http://www.devx.com/dbzone/Article/29685/1954?pf=true refer this link.

QueryCaching is diffferent from the second level caching.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic