-->
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: cache strategy question
PostPosted: Wed Mar 31, 2004 5:30 am 
Newbie

Joined: Wed Mar 31, 2004 5:12 am
Posts: 3
I'm currently planning cache strategy for my content delivery application with high scalability requirements. The basic operation goes like this: first a list of headlines is shown to the user. Once the user clicks one of the headlines, the application fetches the actual content item from the db and displays it to the user. I am using ehcache for content items, which is working fine. Headlines-lists are fetched using createQuery-method and since they are often requested with the same parameters, I'd like to cache them as well. From the documentation I have understood that query cache is the way to go but I have difficulties understanding how it actually works. Could someone please explain what the excerpt below means:

"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."

And also, how do I combine query cache with second level cache?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 6:49 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
if you want to take advantage of cache even for
Quote:
list of headlines


then use iterate() method instead of list()

iterate will ask the db only the id of the resulted objects, then it will iterate on each to obtain full data, it will first hit cache and then the db if the object is not cached.

Note that if the objects are not in cache... this strategy is very expensive.

Just take a look at sql generated...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 10:18 am 
Newbie

Joined: Wed Mar 31, 2004 5:12 am
Posts: 3
Thanks for you reply. I was thinking about using iterator(), but was concerned about the performance. My hibernate code is hidden inside DAO objects, which contain methods that return a List object. The user of DAO object may then do several tricks with a List object such as sort it with certain criteria or combine it with another List object. So returning itarators from DAOs is out of question, instead, I would need to go through the Iteration inside DAO and put objects into a List, which would then be returned to the caller. It might be a bit ugly, but I'm limiting the size of Lists with setMaxResults() so I guess that would not cause much performance penalty though. However, I'm still concerned about iterator() hitting the database on each request for fetching ids, since that is not really necessary, I would rather return the already cached results and refresh the cache periodically.

I may be asking too much and would probably be best off by implementing my own caching for headlines lists, but letting hibernate to do the job would make life much easier (and code much cleaner). Anyway, suggestions and comments are welcome.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 10:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what you can write on your DAO layer is two methods:
getResults() which calls .list()

getCacheableResults() which call iterate() and transform it to a list...


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.