How about this?
Have a local ConcurrentHashMap as your local cache.
Create a Hazelcast distributed map/cache.
Start listening for the distributed map events and update your local ConcurrentHashMap.
Now local caches on each member will be the same. Auto-synched.
import com.hazelcast.core.IMap;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.EntryListener;
import com.hazelcast.core.EntryEvent;
import java.util.concurrent.ConcurrentHashMap;
public class Sample implements EntryListener {
Map localCache = new ConcurrentHashMap ();
public static void main(String[] args) {
Sample sample = new Sample();
IMap map = Hazelcast.getMap("default");
//Listen for all added/updated/removed entries
map.addEntryListener(sample, true);
}
public void entryAdded(EntryEvent event) {
localCache.put(event.getKey(), event.getValue());
}
public void entryRemoved(EntryEvent event) {
localCache.remove(event.getKey());
}
public void entryUpdated(EntryEvent event) {
localCache.put(event.getKey(), event.getValue());
}
}