Package org.axonframework.common.caching
Interface Cache
- All Known Implementing Classes:
AbstractCacheAdapter,EhCacheAdapter,JCacheAdapter,NoCache,WeakReferenceCache
public interface Cache
Abstraction for a Caching mechanism. All Axon component rely on this abstraction, so that different providers can be
plugged in. In future versions, this abstraction may be replaced with the
javax.cache api, as soon as that
api is final.- Since:
- 2.1.2
- Author:
- Allard Buijze
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceInterface describing callback methods, which are invoked when changes are made in the underlying cache.static classAdapter implementation for the EntryListener, allowing for overriding only specific callback methods. -
Method Summary
Modifier and TypeMethodDescriptiondefault <T> TcomputeIfAbsent(Object key, Supplier<T> valueSupplier) Returns the value under the givenkeyin the cache.default <V> voidcomputeIfPresent(Object key, UnaryOperator<V> update) Perform theupdatein the value behind the givenkey.booleancontainsKey(Object key) Indicates whether there is an item stored under givenkey.<K,V> V get(K key) Returns an item from the cache, ornullif no item was stored under that keyvoidStores the givenvaluein the cache, under givenkey.booleanputIfAbsent(Object key, Object value) Stores the givenvaluein the cache, under givenkey, if no element is yet available under that key.registerCacheEntryListener(Cache.EntryListener cacheEntryListener) Registers the givencacheEntryListenerto listen for Cache changes.booleanRemoves the entry stored under givenkey.default voidRemove all stored entries in this cache.
-
Method Details
-
get
<K,V> V get(K key) Returns an item from the cache, ornullif no item was stored under that key- Type Parameters:
K- The type of key usedV- The type of value stored- Parameters:
key- The key under which the item was cached- Returns:
- the item stored under the given key
-
put
Stores the givenvaluein the cache, under givenkey. If an item already exists, it is updated with the new value.- Parameters:
key- The key under which to store the itemvalue- The item to cache
-
putIfAbsent
Stores the givenvaluein the cache, under givenkey, if no element is yet available under that key. This operation is performed atomically.- Parameters:
key- The key under which to store the itemvalue- The item to cache- Returns:
trueif no value was previously assigned to the key,falseotherwise.
-
computeIfAbsent
Returns the value under the givenkeyin the cache. If there is no value present, will invoke the givenvalueSupplier, put the value in the cache and return the produced value.- Parameters:
key- The key under which the item was cached. If not present, this key is used to cache the outcome of thevalueSupplier.valueSupplier- A supplier that lazily supplies the value if there's nokeypresent.- Returns:
- The value that is in the cache after the operation. This can be the original value or the one supplied by
the
valueSupplier.
-
remove
Removes the entry stored under givenkey. If no such entry exists, nothing happens.- Parameters:
key- The key under which the item was stored- Returns:
trueif a value was previously assigned to the key and has been removed,falseotherwise.
-
removeAll
default void removeAll()Remove all stored entries in this cache. -
containsKey
Indicates whether there is an item stored under givenkey.- Parameters:
key- The key to check- Returns:
trueif an item is available under that key,falseotherwise.
-
registerCacheEntryListener
Registers the givencacheEntryListenerto listen for Cache changes.- Parameters:
cacheEntryListener- The listener to register- Returns:
- a handle to deregister the listener
-
computeIfPresent
Perform theupdatein the value behind the givenkey. Theupdateis only executed if there's an entry referencing thekey.- Type Parameters:
V- The type of the value to execute theupdatefor.- Parameters:
key- The key to perform an update for, if not empty.update- The update to perform if thekeyis present.
-