Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Distributed Cache - can multiple applications share same cache?

Tags:

hibernate

I'm looking to setup Hibernate with distributed cache where I have one application writing to the DB and another one reading from the DB. Is there an easy way to notify the reading application when the writing one has written through Hibernate? The distributed cache will invalidate the cache but I need the reading application to know a change has been made to refresh its data immediately.

Thanks, D

like image 895
DD. Avatar asked Jan 15 '11 11:01

DD.


2 Answers

Use a replicating cache such as JBossCache,InfiniSpan or EHCache and configure to replicate updates instead of invalidating cache. e.g. http://docs.jboss.org/jbosscache/1.4.0/TreeCache/en/html/replication.html http://ehcache.org/documentation/distributed_caching.html

like image 82
DD. Avatar answered Oct 18 '22 00:10

DD.


You're not going to get this working without some effort, I think, although all of the components are there to do the individual bits you need.

Specifically, Hibernate has built-in support for JBossCache 2 as a 2nd-level distributed cache. JBossCache does provide an event architecture which allows you to listen to changes in the cache.

The challenge will be to tie the two together, and figure out how to listen to changes in the JBossCache config that hibernate uses. It should be possible, you'll just have to do a bit of reading.

JBossCache2 is a bit old now, but it's the latest version that Hibernate supports out-of-the-box. There is documentation on the JBossCache website for getting v3 working with Hibernate, but that takes extra work.

Edit: It seems that development of JBossCache is being halted in favour of its replacement, Infinispan. There's documentation on how to integrate that with Hibernate.

like image 39
skaffman Avatar answered Oct 18 '22 02:10

skaffman