8.4. Comparing java.util.concurrent.ConcurrentMap and javax.cache.Cache APIs
8.4. Comparing java.util.concurrent.ConcurrentMap and javax.cache.Cache APIs Here is a brief comparison of the data manipulation APIs provided by java.util.concurrent.ConcurrentMap and javax.cache.Cache APIs: Table 8.1. java.util.concurrent.ConcurrentMap and javax.cache.Cache Comparison Operation store and no return N/A store and return value store if not present retrieve delete if present delete and return value delete conditional replace if present replace and return value replace conditional Comparing the two APIs it can be seen that, where possible, JCache avoids returning the value to avoid operations doing expensive network or IO operations. This is an overriding principle in the design of the JCache API. In fact, there is a set of operations that are present in java.util.concurrent.ConcurrentMap , but are not present in the javax.cache.Cache because they could be expensive to compute in a distributed cache. The only exception is iterating over the contents of the cache: Table 8.2. javax.cache.Cache avoiding returns Operation calculate size of cache N/A return all keys in the cache N/A return all values in the cache N/A return all entries in the cache N/A iterate over the cache use iterator() method on keySet, values, or entrySet Report a bug
java.util.concurrent.ConcurrentMap<K,V> javax.cache.Cache<K,V> void put(K key) V put(K key) V getAndPut(K key) V putIfAbsent(K key, V Value) boolean putIfAbsent(K key, V value) V get(Object key) V get(K key) V remove(Object key) boolean remove(K key) V remove(Object key) V getAndRemove(K key) boolean remove(Object key, Object value) boolean remove(K key, V oldValue) V replace(K key, V value) boolean replace(K key, V value) V replace(K key, V value) V getAndReplace(K key, V value) boolean replace(K key, V oldValue, V newValue) boolean replace(K key, V oldValue, V newValue) java.util.concurrent.ConcurrentMap<K,V> javax.cache.Cache<K,V> int size() Set<K> keySet() Collection<V> values() Set<Map.Entry<K, V>> entrySet() Iterator<Cache.Entry<K, V>> iterator()