Map instance.
StampedCommonCache has better performance than ConcurrentCommonCache,
but it is not reentrant, in other words, it may cause deadlock if getAndPut(Object, MemoizeCache.ValueProvider)
or getAndPut(Object, MemoizeCache.ValueProvider, boolean) is called recursively:
readlock -> upgrade to writelock -> readlock (fails to get and waits forever)
| Modifier and Type | Field and Description |
|---|---|
| private final CommonCache | |
| private static final long | |
| private final StampedLock |
| Access | Constructor and Description |
|---|---|
| public | |
| public | StampedCommonCache(int
initial capacity of the cache initialCapacity, int max size of the cache maxSize, EvictableCache.LRU or FIFO, see evictionStrategyEvictableCache.Constructs a cache with limited size |
| public | StampedCommonCache(int
initial capacity of the LRU cache initialCapacity, int max size of the LRU cache maxSize)Constructs a LRU cache with the specified initial capacity and max size. |
| public | StampedCommonCache(int
max size of the LRU cache maxSize)Constructs a LRU cache with the default initial capacity(16) |
| public | StampedCommonCache(Map<K, V>
the map)Map instanceConstructs a cache backed by the specified |
| Modifier and Type | Method and Description |
|---|---|
| public void | cleanUpNullReferences()
Implements org. |
| public Map | |
| private V | compute(K key, MemoizeCache.
|
| public boolean | containsKey(final Object
key whose presence in this cache is to be tested. key)Implements org. |
| public boolean | containsValue(Object
value whose presence in this map is to be tested value)Implements java. true if this map maps one or more keys to the
specified value.
|
| public Object | convertValue(V
the original value value)Implements org. |
| private <R> R | doWithReadLock(EvictableCache.
the content to complete actiondeal with the backed cache guarded by read lock |
| private <R> R | doWithWriteLock(EvictableCache.
the content to complete actiondeal with the backed cache guarded by write lock |
| public Set | entrySet()
Implements java. Set view of the mappings contained in this map.
|
| public V | get(final Object
the key whose associated value is to be returned key)Implements org. |
| public V | getAndPut(K key, MemoizeCache.
provide the value if the associated value not found valueProviderOverrides default org. |
| public V | getAndPut(K key, MemoizeCache.
|
| public boolean | |
| public Set | keys()
Implements org. |
| public Set | |
| public V | put(final K
key with which the specified value is to be associated key, final V value to be associated with the specified key value)Implements org. |
| public void | putAll(Map<? extends K, ? extends V>
mappings to be stored in this map m)Implements java. |
| public V | remove(final Object
of the cached value key)Implements org. |
| public int | |
| public Collection |
| commonCache | back to summary |
|---|---|
| private final CommonCache<K, V> commonCache | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| sl | back to summary |
|---|---|
| private final StampedLock sl | |
| StampedCommonCache | back to summary |
|---|---|
| public StampedCommonCache() Constructs a cache with unlimited size | |
| StampedCommonCache | back to summary |
|---|---|
| public StampedCommonCache(int initialCapacity, int maxSize, EvictableCache. Constructs a cache with limited size
| |
| StampedCommonCache | back to summary |
|---|---|
| public StampedCommonCache(int initialCapacity, int maxSize) Constructs a LRU cache with the specified initial capacity and max size.
The LRU cache is slower than
| |
| StampedCommonCache | back to summary |
|---|---|
| public StampedCommonCache(int maxSize) Constructs a LRU cache with the default initial capacity(16)
| |
| StampedCommonCache | back to summary |
|---|---|
| public StampedCommonCache(Map<K, V> map) Constructs a cache backed by the specified | |
| cleanUpNullReferences | back to summary |
|---|---|
| public void cleanUpNullReferences() Implements org. Doc from org. Invoked when some of the held SoftReferences have been evicted by the garbage collector and so should be removed from the cache. The implementation must ensure that concurrent invocations of all methods on the cache may occur from other threads and thus should protect any shared resources.
| |
| clearAll | back to summary |
|---|---|
| public Map Implements org. Doc from org. Clear the cache | |
| compute | back to summary |
|---|---|
| private V compute(K key, MemoizeCache. | |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(final Object key) Implements org. Doc from org. Determines if the cache contains an entry for the specified key. | |
| containsValue | back to summary |
|---|---|
| public boolean containsValue(Object value) Implements java. Doc from java. Returns | |
| convertValue | back to summary |
|---|---|
| public Object convertValue(V value) Implements org. Doc from org. convert the original value to the target value | |
| doWithReadLock | back to summary |
|---|---|
| private <R> R doWithReadLock(EvictableCache. deal with the backed cache guarded by read lock
| |
| doWithWriteLock | back to summary |
|---|---|
| private <R> R doWithWriteLock(EvictableCache. deal with the backed cache guarded by write lock
| |
| entrySet | back to summary |
|---|---|
| public Set Implements java. Doc from java. Returns a | |
| get | back to summary |
|---|---|
| public V get(final Object key) Implements org. Doc from org. Gets a value from the cache | |
| getAndPut | back to summary |
|---|---|
| public V getAndPut(K key, MemoizeCache. Overrides default org. Doc from org. Try to get the value from cache.
If not found, create the value by
| |
| getAndPut | back to summary |
|---|---|
| public V getAndPut(K key, MemoizeCache. | |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements java. Doc from java. Returns
| |
| keys | back to summary |
|---|---|
| public Set Implements org. Doc from org. Get all keys associated to cached values | |
| keySet | back to summary |
|---|---|
| public Set Implements java. Doc from java. Returns a | |
| put | back to summary |
|---|---|
| public V put(final K key, final V value) Implements org. Doc from org. Associates the specified value with the specified key in the cache.
| |
| putAll | back to summary |
|---|---|
| public void putAll(Map<? extends K, ? extends V> m) Implements java. Doc from java. Copies all of the mappings from the specified map to this map
(optional operation). The effect of this call is equivalent to that
of calling | |
| remove | back to summary |
|---|---|
| public V remove(final Object key) Implements org. Doc from org. Remove the cached value by the key | |
| size | back to summary |
|---|---|
| public int size() Implements org. Doc from org. Get the size of the cache
| |
| values | back to summary |
|---|---|
| public Collection Implements org. Doc from org. Get all cached values
| |