9.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:
Expand
Table 9.1. java.util.concurrent.ConcurrentMap and javax.cache.Cache Comparison
Operation
java.util.concurrent.ConcurrentMap<K,V>
Copy to Clipboard Toggle word wrap
javax.cache.Cache<K,V>
Copy to Clipboard Toggle word wrap
store and no return N/A
void put(K key)
Copy to Clipboard Toggle word wrap
store and return previous value
V put(K key)
Copy to Clipboard Toggle word wrap
V getAndPut(K key)
Copy to Clipboard Toggle word wrap
store if not present
V putIfAbsent(K key, V Value)
Copy to Clipboard Toggle word wrap
boolean putIfAbsent(K key, V value)
Copy to Clipboard Toggle word wrap
retrieve
V get(Object key)
Copy to Clipboard Toggle word wrap
V get(K key)
Copy to Clipboard Toggle word wrap
delete if present
V remove(Object key)
Copy to Clipboard Toggle word wrap
boolean remove(K key)
Copy to Clipboard Toggle word wrap
delete and return previous value
V remove(Object key)
Copy to Clipboard Toggle word wrap
V getAndRemove(K key)
Copy to Clipboard Toggle word wrap
delete conditional
boolean remove(Object key, Object value)
Copy to Clipboard Toggle word wrap
boolean remove(K key, V oldValue)
Copy to Clipboard Toggle word wrap
replace if present
V replace(K key, V value)
Copy to Clipboard Toggle word wrap
boolean replace(K key, V value)
Copy to Clipboard Toggle word wrap
replace and return previous value
V replace(K key, V value)
Copy to Clipboard Toggle word wrap
V getAndReplace(K key, V value)
Copy to Clipboard Toggle word wrap
replace conditional
boolean replace(K key, V oldValue, V newValue)
Copy to Clipboard Toggle word wrap
boolean replace(K key, V oldValue, V newValue)
Copy to Clipboard Toggle word wrap
Comparing the two APIs it can be seen that, where possible, JCache avoids returning the previous 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:
Expand
Table 9.2. javax.cache.Cache avoiding returns
Operation
java.util.concurrent.ConcurrentMap<K,V>
Copy to Clipboard Toggle word wrap
javax.cache.Cache<K,V>
Copy to Clipboard Toggle word wrap
calculate size of cache
int size()
Copy to Clipboard Toggle word wrap
N/A
return all keys in the cache
Set<K> keySet()
Copy to Clipboard Toggle word wrap
N/A
return all values in the cache
Collection<V> values()
Copy to Clipboard Toggle word wrap
N/A
return all entries in the cache
Set<Map.Entry<K, V>> entrySet()
Copy to Clipboard Toggle word wrap
N/A
iterate over the cache use iterator() method on keySet, values, or entrySet
Iterator<Cache.Entry<K, V>> iterator()
Copy to Clipboard Toggle word wrap
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2026 Red Hat
Back to top