views:

51

answers:

3

hi, I am building a web application and I want to manage cache for several objects, so I don't have to go to the DB each time. my problem is that this objects`s data can be modified by other application on the DB. Does anyone knows a good pattern to keep my cached objects in sync with the BD?. I read this article (www.developer.com/java/other/article.php/630481) but it does not addresses this problem.

A: 

Are you working in Java, or another language? In .Net there is the SqlCacheDependency (http://msdn.microsoft.com/en-us/library/ms178604.aspx).

ilivewithian
+1  A: 

A good pattern is the "observer pattern". The idea is that any application which changes an object sends the object's ID to a central place where anyone using objects can register themselves. When an event is received, all listeners get a message with the object's ID so they can update their caches (or flush them).

Aaron Digulla
A: 

A good starting point might be the documentation of ehcache, in particular the chapter Distributed Caching with ehcache. ehcache is a popular cache framework in Java.

markusk