Package org.axonframework.common.caching
Class EhCacheAdapter
java.lang.Object
org.axonframework.common.caching.AbstractCacheAdapter<org.ehcache.event.CacheEventListener>
org.axonframework.common.caching.EhCacheAdapter
- All Implemented Interfaces:
Cache
Cache implementation that delegates all calls to an EhCache instance.
- Since:
- 2.1.2
- Author:
- Allard Buijze, Gerard Klijs
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.axonframework.common.caching.Cache
Cache.EntryListener, Cache.EntryListenerAdapter -
Constructor Summary
ConstructorsConstructorDescriptionEhCacheAdapter(org.ehcache.core.Ehcache ehCache) Initialize the adapter to forward all call to the givenehCacheinstance -
Method Summary
Modifier and TypeMethodDescription<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.protected org.ehcache.event.CacheEventListenercreateListenerAdapter(Cache.EntryListener cacheEntryListener) Creates an adapter for the givencacheEntryListener.protected RegistrationdoRegisterListener(org.ehcache.event.CacheEventListener listenerAdapter) Registers the given listener with the cache implementation<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.booleanRemoves the entry stored under givenkey.voidRemove all stored entries in this cache.Methods inherited from class org.axonframework.common.caching.AbstractCacheAdapter
registerCacheEntryListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.common.caching.Cache
computeIfAbsent
-
Constructor Details
-
EhCacheAdapter
public EhCacheAdapter(org.ehcache.core.Ehcache ehCache) Initialize the adapter to forward all call to the givenehCacheinstance- Parameters:
ehCache- The cache instance to forward calls to
-
-
Method Details
-
get
public <K,V> V get(K key) Description copied from interface:CacheReturns 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
Description copied from interface:CacheStores 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
Description copied from interface:CacheStores 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.
-
remove
Description copied from interface:CacheRemoves 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
public void removeAll()Description copied from interface:CacheRemove all stored entries in this cache. -
containsKey
Description copied from interface:CacheIndicates whether there is an item stored under givenkey.- Parameters:
key- The key to check- Returns:
trueif an item is available under that key,falseotherwise.
-
computeIfPresent
Description copied from interface:CachePerform 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.
-
createListenerAdapter
protected org.ehcache.event.CacheEventListener createListenerAdapter(Cache.EntryListener cacheEntryListener) Description copied from class:AbstractCacheAdapterCreates an adapter for the givencacheEntryListener. The adapter must forward all incoming notifications to the respective methods on thecacheEntryListener.- Specified by:
createListenerAdapterin classAbstractCacheAdapter<org.ehcache.event.CacheEventListener>- Parameters:
cacheEntryListener- The listener to create an adapter for- Returns:
- an adapter that forwards notifications
-
doRegisterListener
Description copied from class:AbstractCacheAdapterRegisters the given listener with the cache implementation- Specified by:
doRegisterListenerin classAbstractCacheAdapter<org.ehcache.event.CacheEventListener>- Parameters:
listenerAdapter- the listener to register- Returns:
- a handle to deregister the listener
-