public interface Cache
javax.cache
api, as soon as that
api is final.Modifier and Type | Interface and Description |
---|---|
static interface |
Cache.EntryListener
Interface describing callback methods, which are invoked when changes are made in the underlying cache.
|
static class |
Cache.EntryListenerAdapter
Adapter implementation for the EntryListener, allowing for overriding only specific callback methods.
|
Modifier and Type | Method and Description |
---|---|
default <T> T |
computeIfAbsent(Object key,
Supplier<T> valueSupplier)
Returns the value under the given
key in the cache. |
default <V> void |
computeIfPresent(Object key,
UnaryOperator<V> update)
Perform the
update in the value behind the given key . |
boolean |
containsKey(Object 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 |
void |
put(Object key,
Object value)
Stores the given
value in the cache, under given key . |
boolean |
putIfAbsent(Object key,
Object value)
Stores the given
value in the cache, under given key , if no element is yet available under that
key. |
Registration |
registerCacheEntryListener(Cache.EntryListener cacheEntryListener)
Registers the given
cacheEntryListener to listen for Cache changes. |
boolean |
remove(Object key)
Removes the entry stored under given
key . |
default void |
removeAll()
Remove all stored entries in this cache.
|
<K,V> V get(K key)
null
if no item was stored under that keyK
- The type of key usedV
- The type of value storedkey
- The key under which the item was cachedvoid put(Object key, Object value)
value
in the cache, under given key
. If an item already exists, it is updated
with the new value.key
- The key under which to store the itemvalue
- The item to cacheboolean putIfAbsent(Object key, Object value)
value
in the cache, under given key
, if no element is yet available under that
key. This operation is performed atomically.key
- The key under which to store the itemvalue
- The item to cachetrue
if no value was previously assigned to the key, false
otherwise.default <T> T computeIfAbsent(Object key, Supplier<T> valueSupplier)
key
in the cache. If there is no value present, will invoke the given
valueSupplier
, put the value in the cache and return the produced value.key
- The key under which the item was cached. If not present, this key is used to cache the
outcome of the valueSupplier
.valueSupplier
- A supplier that lazily supplies the value if there's no key
present.valueSupplier
.boolean remove(Object key)
key
. If no such entry exists, nothing happens.key
- The key under which the item was storedtrue
if a value was previously assigned to the key and has been removed, false
otherwise.default void removeAll()
boolean containsKey(Object key)
key
.key
- The key to checktrue
if an item is available under that key, false
otherwise.Registration registerCacheEntryListener(Cache.EntryListener cacheEntryListener)
cacheEntryListener
to listen for Cache changes.cacheEntryListener
- The listener to registerdefault <V> void computeIfPresent(Object key, UnaryOperator<V> update)
update
in the value behind the given key
. The update
is only executed if
there's an entry referencing the key
.V
- The type of the value to execute the update
for.key
- The key to perform an update for, if not empty.update
- The update to perform if the key
is present.Copyright © 2010–2024. All rights reserved.