Hello everyone - I have a quick question on object caching in a distributed J2EE system. Any ideas on a good solution?
I'm looking at OSCache, EHCache, Memcached, JCS, etc?
Any help and/or previous implementations knowledge would greatly help.
While you are researching the existing caching frameworks, I would like to suggest the following, which you have to implement yourself (if nothing is available ready made).
1. Write a simple caching mechanism which is available in each of the system in the distributed environment.
2. write a MDB - publisher/subscriber model
3. whenever the cache needs to be invalidated, publish it, and all the subscribers i.e. the caching component in each distributed environment will invalidate their cache. Thus, when there is a request for data which is invalidated (i.e. not available in the cache), then you proceed to retrieve the data and fill the cache.
(I have used this approach earlier, the difference is instead of MDB I used a database trigger to invalidate cache on all the systems, and i did not find any problem). It worked fine and maintaining it was also easy since i wrote it!! The advantage here is unlike other caching mechanism which replicates cached data from system 1 to system 2 etc, the cache here is built based on the requests this system handles. Also, storing the cached data into disk is unnecessary unless you know for sure that retrieving that data from DB is much slower.
I worked with OSCache and it is very simple to use frame work. It was tested in clustered environment as well.
I think you will be using this cache at the ejb tier then only OSCache will work in cluster environment, if you want to use the cache at the web tier OSCache will not work in cluster enviroment.
Have a look at JGroups cache, I had used it, its pretty simple to implement and doesnt involve the overheads of the caching products u mentioned