Java caching in a distributed environment
I have to create a simple replicated cache using java internally to be used in a distributed environment. I saw oracle implement the Replicated Caching Service .
The problem I am running into is doing an update or delete, I get a lock in another cache until the cache is updated and notify others of this change. This ultimately happens in a deadlock situation when deleting. Is there any strategy I should follow when updating or deleting from the cache.
- Is it possible to implement a replicated cache without a primary cache?
a source to share
You can check out Gigaspaces XAP , which is a fully transactional gridded memory data grid that supports many other things, fully replicated topologies.
Disclaimer - I work for gigaspaces.
Eitan
a source to share
How about Java Caching System, JCS: http://jakarta.apache.org/jcs/
I have tested lateral cache cache (using UDP Discovery Service) http://jakarta.apache.org/jcs/LateralTCPProperties.html
a source to share
JCS should do the job for you as it has good flexibility in terms of project configurations. Also an attractive feature is lazy loading data when we talk about replication, where only the required data is replicated based on the request to get that object. This reduces the memory footprint.
Have a look at Remote Cache Server with JCS on the JAC Apache site.
a source to share
I would recommend using MemCached. It has out-of-memory process storage (on dedicated cache servers). In addition, the cache server is written in C / C ++ and good runtime performance is achieved with low CPU hit and good memory usage. See: http://memcached.org
There is a pretty good Java client for connecting to the server. See: http://code.google.com/p/spymemcached
Regarding multiple cache servers and the mechanism for choosing which server should go to ... here is a portion from the article below:
In its default configuration, the Memcached client uses very simple logic to select a server for a get or set operation. When you do a get () or set (), the client takes the cache key and calls its hashCode () to get an integer such as 11. It then takes a number and divides it by the number of Memcached servers available, say two. It then takes the remainder value, which is 1 in this case. The cache entry will be sent to the Memcached 1 server. This simple algorithm ensures that the Memcached client on each of your application servers always selects the same server for a given cache key.
And the article is here:
Using Memcached Server Performance for Java Part 1 : Architecture and Configuration http://www.javaworld.com/javaworld/jw-04-2012/120418-memcached-for-java-enterprise-performance.html
Leveraging Memcached Server Performance for Java Part 2 : Database Driven Web Applications http://www.javaworld.com/javaworld/jw-05-2012/120515-memcached-for-java-enterprise-performance-2.html
a source to share