Class UnlimitedConcurrentCache<K,V>
java.lang.Object
org.codehaus.groovy.runtime.memoize.UnlimitedConcurrentCache<K,V>
- All Implemented Interfaces:
java.io.Serializable
,java.util.Map<K,V>
,EvictableCache<K,V>
,MemoizeCache<K,V>
@ThreadSafe public final class UnlimitedConcurrentCache<K,V> extends java.lang.Object implements EvictableCache<K,V>, java.io.Serializable
A cache backed by a ConcurrentHashMap
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.codehaus.groovy.runtime.memoize.EvictableCache
EvictableCache.Action<K,V,R>, EvictableCache.EvictionStrategy
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K extends java.lang.Object,V extends java.lang.Object>
Nested classes/interfaces inherited from interface org.codehaus.groovy.runtime.memoize.MemoizeCache
MemoizeCache.ValueProvider<K,V>
-
Constructor Summary
Constructors Constructor Description UnlimitedConcurrentCache()
Constructs a cache with unlimited sizeUnlimitedConcurrentCache(int initialCapacity)
Constructs a cache with unlimited size and set its initial capacityUnlimitedConcurrentCache(java.util.Map<? extends K,? extends V> m)
Constructs a cache and initialize the cache with the specified map -
Method Summary
Modifier and Type Method Description void
cleanUpNullReferences()
Replying on the ConcurrentHashMap thread-safe iteration implementation the method will remove all entries holding SoftReferences to gc-evicted objects.java.util.Map<K,V>
clearAll()
Clear the cacheboolean
containsKey(java.lang.Object key)
Determines if the cache contains an entry for the specified key.boolean
containsValue(java.lang.Object value)
java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
V
get(java.lang.Object key)
Gets a value from the cacheV
getAndPut(K key, MemoizeCache.ValueProvider<? super K,? extends V> valueProvider)
Try to get the value from cache.boolean
isEmpty()
java.util.Set<K>
keys()
Get all keys associated to cached valuesjava.util.Set<K>
keySet()
V
put(K key, V value)
Associates the specified value with the specified key in the cache.void
putAll(java.util.Map<? extends K,? extends V> m)
V
remove(java.lang.Object key)
Remove the cached value by the keyint
size()
Get the size of the cachejava.util.Collection<V>
values()
Get all cached valuesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.codehaus.groovy.runtime.memoize.EvictableCache
clear
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
UnlimitedConcurrentCache
public UnlimitedConcurrentCache()Constructs a cache with unlimited size -
UnlimitedConcurrentCache
public UnlimitedConcurrentCache(int initialCapacity)Constructs a cache with unlimited size and set its initial capacity- Parameters:
initialCapacity
- the initial capacity
-
UnlimitedConcurrentCache
Constructs a cache and initialize the cache with the specified map- Parameters:
m
- the map to initialize the cache
-
-
Method Details
-
remove
Remove the cached value by the key -
putAll
-
keySet
-
clearAll
Clear the cache- Specified by:
clearAll
in interfaceEvictableCache<K,V>
- Returns:
- returns the content of the cleared map
-
values
Get all cached values -
entrySet
-
keys
Get all keys associated to cached values- Specified by:
keys
in interfaceEvictableCache<K,V>
- Returns:
- all keys
-
containsKey
public boolean containsKey(java.lang.Object key)Determines if the cache contains an entry for the specified key.- Specified by:
containsKey
in interfaceEvictableCache<K,V>
- Specified by:
containsKey
in interfacejava.util.Map<K,V>
- Parameters:
key
- key whose presence in this cache is to be tested.- Returns:
- true if the cache contains a mapping for the specified key
-
containsValue
public boolean containsValue(java.lang.Object value) -
size
public int size()Get the size of the cache -
isEmpty
public boolean isEmpty() -
put
Associates the specified value with the specified key in the cache.- Specified by:
put
in interfacejava.util.Map<K,V>
- Specified by:
put
in interfaceMemoizeCache<K,V>
- Parameters:
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified key- Returns:
- null, or the old value if the key associated with the specified key.
-
get
Gets a value from the cache -
getAndPut
Try to get the value from cache. If not found, create the value byMemoizeCache.ValueProvider
and put it into the cache, at last return the value.- Specified by:
getAndPut
in interfaceMemoizeCache<K,V>
- Parameters:
key
-valueProvider
- provide the value if the associated value not found- Returns:
- the cached value
-
cleanUpNullReferences
public void cleanUpNullReferences()Replying on the ConcurrentHashMap thread-safe iteration implementation the method will remove all entries holding SoftReferences to gc-evicted objects.- Specified by:
cleanUpNullReferences
in interfaceMemoizeCache<K,V>
-