K - type of the keysV - type of the valuespublic class CommonCache<K,V> extends java.lang.Object implements EvictableCache<K,V>, ValueConvertable<V,java.lang.Object>, java.io.Serializable
Map instanceEvictableCache.EvictionStrategyMemoizeCache.ValueProvider<K,V>| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_INITIAL_CAPACITY
The default initial capacity
|
static float |
DEFAULT_LOAD_FACTOR
The default load factor
|
| Constructor and Description |
|---|
CommonCache()
Constructs a cache with unlimited size
|
CommonCache(int maxSize)
Constructs a LRU cache with the default initial capacity
|
CommonCache(int initialCapacity,
int maxSize)
Constructs a LRU cache with the specified initial capacity and max size.
|
CommonCache(int initialCapacity,
int maxSize,
EvictableCache.EvictionStrategy evictionStrategy)
Constructs a cache with limited size
|
CommonCache(java.util.Map<K,V> map)
Constructs a cache backed by the specified
Map instance |
| Modifier and Type | Method and Description |
|---|---|
void |
cleanUpNullReferences()
Invoked when some of the held SoftReferences have been evicted by the garbage collector and so should be removed from the cache.
|
void |
clear()
Clear the cache
|
java.util.Map<K,V> |
clearAll()
Clear the cache
|
boolean |
containsKey(java.lang.Object key)
Determines if the cache contains an entry for the specified key.
|
boolean |
containsValue(java.lang.Object value) |
java.lang.Object |
convertValue(V value)
convert the original value to the target value
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
V |
get(java.lang.Object key)
Gets a value from the cache
|
V |
getAndPut(K key,
MemoizeCache.ValueProvider<? super K,? extends V> valueProvider)
Try to get the value from cache.
|
V |
getAndPut(K key,
MemoizeCache.ValueProvider<? super K,? extends V> valueProvider,
boolean shouldCache) |
boolean |
isEmpty() |
java.util.Set<K> |
keys()
Get all keys associated to cached values
|
java.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 key
|
int |
size()
Get the size of the cache
|
java.lang.String |
toString() |
java.util.Collection<V> |
values()
Get all cached values
|
public static final float DEFAULT_LOAD_FACTOR
public static final int DEFAULT_INITIAL_CAPACITY
public CommonCache()
public CommonCache(int initialCapacity,
int maxSize,
EvictableCache.EvictionStrategy evictionStrategy)
initialCapacity - initial capacity of the cachemaxSize - max size of the cacheevictionStrategy - LRU or FIFO, see EvictableCache.EvictionStrategypublic CommonCache(int initialCapacity,
int maxSize)
LRUCacheinitialCapacity - initial capacity of the LRU cachemaxSize - max size of the LRU cachepublic CommonCache(int maxSize)
maxSize - max size of the LRU cacheCommonCache(int, int)public V get(java.lang.Object key)
public V put(K key, V value)
put in interface java.util.Map<K,V>put in interface MemoizeCache<K,V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublic V getAndPut(K key, MemoizeCache.ValueProvider<? super K,? extends V> valueProvider)
MemoizeCache.ValueProvider and put it into the cache, at last return the valuegetAndPut in interface MemoizeCache<K,V>public V getAndPut(K key, MemoizeCache.ValueProvider<? super K,? extends V> valueProvider, boolean shouldCache)
public java.util.Collection<V> values()
public java.util.Set<K> keys()
keys in interface EvictableCache<K,V>public boolean containsValue(java.lang.Object value)
public boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<K,V>containsKey in interface EvictableCache<K,V>key - key whose presence in this cache is to be tested.public int size()
public V remove(java.lang.Object key)
public java.util.Map<K,V> clearAll()
clearAll in interface EvictableCache<K,V>public void clear()
clear in interface java.util.Map<K,V>clearAll()public void cleanUpNullReferences()
cleanUpNullReferences in interface MemoizeCache<K,V>public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.Object convertValue(V value)
convertValue in interface ValueConvertable<V,java.lang.Object>value - the original value