I've been using Singleton-EJBs in this fashion (as shown by Adam Bien in his blog):
@Singleton
public class MyCache {
ConcurrentHashMap<String, Object> myMap= new ConcurrentHashMap<String, Object<>();
//...Crud methods to the map
}
Now with JCache being a candidate for java-ee-8 i read the following in the JCache spec:
A Cache is a Map-like data-structure that permits the temporary storage of Key-based Values. A Cache is owned by a single CacheManager.
Assuming JCache makes it into the next java-ee spec, should something else be prefered over above?
What additional features will JCache API enable?
JCache will be very interesting now that it has been submitted as final in Java EE 8, and is getting more widespread vendor support.
In particular, one of the things enabled that is intriguing is the support for Entry Processor which is a way of talking to distributed data that maximizes in-memory performance with a minimum of locking and concurrency issues by using distributed processing across your cluster.
JCache looks like a fundamentally new way of looking at plain old caching, which migrates the whole conversation towards fully distributed caches that leverage both RAM and CPU across the cluster. This takes care of distributed computing in a more cloud-friendly (read: elastically scalable) way than local caching and in a way that leverages distributed processing in addition to distributed RAM.