-->
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.  [ 8 posts ] 
Author Message
 Post subject: How "intelligent" is second level caching?
PostPosted: Fri Oct 27, 2006 10:03 am 
Newbie

Joined: Fri Oct 27, 2006 9:22 am
Posts: 3
Having a play around with Hibernate 3.2.0 and the second level caching.

My question is:

How "intelligent" is this caching?

I don't mean smart caching as in it know of the majority of the cache hits, etc. I'm after something like Hibernate being able to detect changes made on the database and then update the cache accordingly.

Typical scenario would be reporting apps refering to a web services built with Hibernate for the integration service layer.

If Hibernate only just caches in the data, is there any framework out there that adds the intelligence? If failing that, how about a development guideline?

Thanks in advance.


Shah.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 11:05 pm 
Newbie

Joined: Sat Jul 29, 2006 4:51 am
Posts: 11
Shah,

The second level cache architecture in hibernate3 is simply that, a "cache." It is limited in the fact that it can only expire objects in the cache based on a timeout. Also, according to the cache documentation it CANNOT detect changes made to the database by other applications or processes.

As for adding intellegence to the cache you might consider writing your own cache plugin coupled with some auxillary support classes to add an intellegent cache to hibernate.

Take a look at the JavaDoc for org.hibernate.cache !

Hope this helps.

--------------------------------------------
Nathan


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 29, 2006 3:18 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
It is unclear from the original post what exacly you expect the cache to perform, and how it should be used. Does it only detect outside changes? What about addition/removal of objects?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 6:32 am 
Newbie

Joined: Fri Oct 27, 2006 9:22 am
Posts: 3
Okay. As I've guessed from the first response that the 2nd level cache mechanism used in Hibernate just does straightforward caching. Many thanks for the response.

This means I'll have to implement the "intelligence" myself.

I just wanted the cache to be slightly intelligent to be able to monitor data changes on the database. If so, then the cached data would then be set to stale, indicating that the cache needs to be updated. I guess this can then be automated by instantiating the update process via a Thread.

Perhaps the above can be implemented, but I was wondering if Hibernate would have this *special feature*.

I'm not sure if there is an alternative library out there that perhaps does this?

Thanks for the input guys.


Shah.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 6:38 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
In my project, I have created a small mechanism to periodically refresh my objects, ON DEMAND, that is: I only refresh specific objects that my app was instructed to refresh (such commands reach the app via some networking component). This is because changes are relatively rare in my case, so there is no point in refreshing entire object graphs...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 6:58 am 
Newbie

Joined: Fri Oct 27, 2006 9:22 am
Posts: 3
A third mechanism is to provide user with a button to refresh the cached data on demand and direct. But this way, users would have to wait for the process to complete. So I guess updating the cache periodically helps for the user experience.

So that makes it three ideas (one being bad):

1) Periodically update specific cached objects when instructed via the app.

2) Periodically check the database for changes (i.e. timestamp check) and update the cache accordingly.

3) Provide user interface to allow users to update cache on demand (can lead to long waits :-( ).

Anyone open to other suggestions/ideas?

BTW, does hibernate allow for CRON type scheduling when using EHCACHE? I know OSCACHE has this feature built in, but just wondering if this can be configured under Hibernate and/or Spring.

Thanks for the mega quick response!


Shah.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 7:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hibernate doesn't care what the specific second level cache does as long as it obeys the Cache and CacheProvider API.

So "detection of external changes and refresh" is perfectly fine (its event the intent) to do on the actual specific cache and/or just use the Hibernate API to evict stuff from the cache.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 7:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hibernate doesn't care what the specific second level cache does as long as it obeys the Cache and CacheProvider API.

So "detection of external changes and refresh" is perfectly fine (its event the intent) to do on the actual specific cache and/or just use the Hibernate API to evict stuff from the cache.

_________________
Max
Don't forget to rate


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