public class WeakReferenceCache extends Object implements Cache
Cache.EntryListener, Cache.EntryListenerAdapter
Constructor and Description |
---|
WeakReferenceCache() |
Modifier and Type | Method and Description |
---|---|
<K> boolean |
containsKey(K key)
Indicates whether there is an item stored under given
key . |
<K,V> V |
get(K key)
Returns an item from the cache, or
null if no item was stored under that key |
<K,V> void |
put(K key,
V value)
Stores the given
value in the cache, under given key . |
<K,V> boolean |
putIfAbsent(K key,
V value)
Stores the given
value in the cache, under given key , if no element is yet available
under that key. |
Registration |
registerCacheEntryListener(Cache.EntryListener entryListener)
Registers the given
cacheEntryListener to listen for Cache changes. |
<K> boolean |
remove(K key)
Removes the entry stored under given
key . |
public Registration registerCacheEntryListener(Cache.EntryListener entryListener)
Cache
cacheEntryListener
to listen for Cache changes.registerCacheEntryListener
in interface Cache
entryListener
- The listener to registerpublic <K,V> V get(K key)
Cache
null
if no item was stored under that keypublic <K,V> void put(K key, V value)
Cache
value
in the cache, under given key
. If an item already exists,
it is updated with the new value.public <K,V> boolean putIfAbsent(K key, V value)
Cache
value
in the cache, under given key
, if no element is yet available
under that key. This operation is performed atomically.putIfAbsent
in interface Cache
K
- The type of key usedV
- The type of value storedkey
- The key under which to store the itemvalue
- The item to cachetrue
if no value was previously assigned to the key, false
otherwise.public <K> boolean remove(K key)
Cache
key
. If no such entry exists, nothing happens.public <K> boolean containsKey(K key)
Cache
key
.containsKey
in interface Cache
K
- The type of keykey
- The key to checktrue
if an item is available under that key, false
otherwise.Copyright © 2010–2017. All rights reserved.