Class UnlimitedConcurrentCache<K,V>
java.lang.Object
org.codehaus.groovy.runtime.memoize.UnlimitedConcurrentCache<K,V>
- All Implemented Interfaces:
Serializable,Map<K,,V> EvictableCache<K,,V> MemoizeCache<K,V>
@ThreadSafe
public final class UnlimitedConcurrentCache<K,V>
extends Object
implements EvictableCache<K,V>, Serializable
A cache backed by a ConcurrentHashMap
- See Also:
-
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
Map.Entry<K extends Object,V extends Object> Nested classes/interfaces inherited from interface org.codehaus.groovy.runtime.memoize.MemoizeCache
MemoizeCache.ValueProvider<K,V> -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a cache with unlimited sizeUnlimitedConcurrentCache(int initialCapacity) Constructs a cache with unlimited size and set its initial capacityUnlimitedConcurrentCache(Map<? extends K, ? extends V> m) Constructs a cache and initialize the cache with the specified map -
Method Summary
Modifier and TypeMethodDescriptionvoidReplying on the ConcurrentHashMap thread-safe iteration implementation the method will remove all entries holding SoftReferences to gc-evicted objects.clearAll()Clear the cachebooleancontainsKey(Object key) Determines if the cache contains an entry for the specified key.booleancontainsValue(Object value) Determines whether the cache contains the specified stored value.entrySet()Returns a live view of the cache entries.Gets a value from the cachegetAndPut(K key, MemoizeCache.ValueProvider<? super K, ? extends V> valueProvider) Try to get the value from cache.booleanisEmpty()Returns whether the cache currently holds no entries.keys()Get all keys associated to cached valueskeySet()Returns a live view of the keys in this cache.Associates the specified value with the specified key in the cache.voidCopies all mappings from the supplied map into this cache.Remove the cached value by the keyintsize()Get the size of the cachevalues()Get all cached valuesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.runtime.memoize.EvictableCache
clearMethods 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
Copies all mappings from the supplied map into this cache. -
keySet
Returns a live view of the keys in this cache. -
clearAll
Clear the cache- Specified by:
clearAllin interfaceEvictableCache<K,V> - Returns:
- returns the content of the cleared map
-
values
Get all cached values -
entrySet
Returns a live view of the cache entries. -
keys
Get all keys associated to cached values- Specified by:
keysin interfaceEvictableCache<K,V> - Returns:
- all keys
-
containsKey
Determines if the cache contains an entry for the specified key.- Specified by:
containsKeyin interfaceEvictableCache<K,V> - Specified by:
containsKeyin interfaceMap<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
Determines whether the cache contains the specified stored value.- Specified by:
containsValuein interfaceMap<K,V> - Parameters:
value- the value whose presence should be tested- Returns:
trueif the cache contains the value
-
size
public int size()Get the size of the cache -
isEmpty
public boolean isEmpty()Returns whether the cache currently holds no entries. -
put
Associates the specified value with the specified key in the cache. -
get
Gets a value from the cache -
getAndPut
Try to get the value from cache. If not found, create the value byMemoizeCache.ValueProviderand put it into the cache, at last return the value.- Specified by:
getAndPutin interfaceMemoizeCache<K,V> - Parameters:
key- the key to look upvalueProvider- provide the value if the associated value not found- Returns:
- the cached or newly created 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:
cleanUpNullReferencesin interfaceMemoizeCache<K,V>
-