Class StronglyConsistentCacheAccessor
- java.lang.Object
-
- net.sf.ehcache.constructs.EhcacheDecoratorAdapter
-
- net.sf.ehcache.constructs.eventual.StronglyConsistentCacheAccessor
-
- All Implemented Interfaces:
java.lang.Cloneable,Ehcache,InternalEhcache
public class StronglyConsistentCacheAccessor extends EhcacheDecoratorAdapter
StronglyConsistentCacheAccessor is a decorator that accepts distributed caches configured with eventual consistency.The accessor will then lock for all operations:
- using a read lock for read operations
- using a write lock for write operations
- using a write lock and compound operations for the CAS operations
- Author:
- Louis Jacomet
-
-
Field Summary
-
Fields inherited from class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
underlyingCache
-
-
Constructor Summary
Constructors Constructor Description StronglyConsistentCacheAccessor(Ehcache underlyingCache)Constructor accepting the cache to be decorated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Elementget(java.io.Serializable key)Gets an element from the cache.Elementget(java.lang.Object key)Gets an element from the cache.java.util.Map<java.lang.Object,Element>getAll(java.util.Collection<?> keys)Gets all the elements from the cache for the keys provided.java.util.MapgetAllWithLoader(java.util.Collection keys, java.lang.Object loaderArgument)The getAll method will return, from the cache, a Map of the objects associated with the Collection of keys in argument "keys".ElementgetQuiet(java.io.Serializable key)Gets an element from the cache, without updating Element statistics.ElementgetQuiet(java.lang.Object key)Gets an element from the cache, without updating Element statistics.ElementgetWithLoader(java.lang.Object key, CacheLoader loader, java.lang.Object loaderArgument)This method will return, from the cache, the object associated with the argument "key".voidput(Element element)Put an element in the cache.voidput(Element element, boolean doNotNotifyCacheReplicators)Put an element in the cache.voidputAll(java.util.Collection<Element> elements)Puts a collection of elements in to the cache.ElementputIfAbsent(Element element)Put an element in the cache if no element is currently mapped to the elements key.ElementputIfAbsent(Element element, boolean doNotNotifyCacheReplicators)Put an element in the cache if no element is currently mapped to the elements key.voidputQuiet(Element element)Put an element in the cache, without updating statistics, or updating listeners.voidputWithWriter(Element element)Put an element in the cache writing through a CacheWriter.booleanremove(java.io.Serializable key)Removes anElementfrom the Cache.booleanremove(java.io.Serializable key, boolean doNotNotifyCacheReplicators)Removes anElementfrom the Cache.booleanremove(java.lang.Object key)Removes anElementfrom the Cache.booleanremove(java.lang.Object key, boolean doNotNotifyCacheReplicators)Removes anElementfrom the Cache.voidremoveAll(java.util.Collection<?> keys)Removes given set ofElementfrom the Cache.voidremoveAll(java.util.Collection<?> keys, boolean doNotNotifyCacheReplicators)Removes all cached items.ElementremoveAndReturnElement(java.lang.Object key)Removes and returns the element associated with the keybooleanremoveElement(Element element)Remove the Element mapped to the key for the supplied element if the value of the supplied Element compares equal to the value of the cached Element.booleanremoveQuiet(java.io.Serializable key)Removes anElementfrom the Cache, without notifying listeners.booleanremoveQuiet(java.lang.Object key)Removes anElementfrom the Cache, without notifying listeners.booleanremoveWithWriter(java.lang.Object key)Removes anElementfrom the Cache and any stores it might be in.Elementreplace(Element element)Replace the cached element only if an Element is currently cached for this keybooleanreplace(Element old, Element element)Replace the cached element only if the current Element is equal to the supplied old Element.-
Methods inherited from class net.sf.ehcache.constructs.EhcacheDecoratorAdapter
acquireReadLockOnKey, acquireWriteLockOnKey, addPropertyChangeListener, bootstrap, calculateInMemorySize, calculateOffHeapSize, calculateOnDiskSize, clone, createQuery, disableDynamicFeatures, dispose, evictExpiredElements, flush, getBootstrapCacheLoader, getCacheConfiguration, getCacheEventNotificationService, getCacheExceptionHandler, getCacheManager, getDiskStoreSize, getGuid, getInternalContext, getKeys, getKeysNoDuplicateCheck, getKeysWithExpiryCheck, getMemoryStoreSize, getName, getOffHeapStoreSize, getRegisteredCacheExtensions, getRegisteredCacheLoaders, getRegisteredCacheWriter, getSearchAttribute, getSearchAttributes, getSize, getStatistics, getStatus, getWriterManager, hasAbortedSizeOf, initialise, isClusterBulkLoadEnabled, isClusterCoherent, isDisabled, isElementInMemory, isElementInMemory, isElementOnDisk, isElementOnDisk, isExpired, isKeyInCache, isNodeBulkLoadEnabled, isNodeCoherent, isReadLockedByCurrentThread, isSearchable, isValueInCache, isWriteLockedByCurrentThread, load, loadAll, recalculateSize, registerCacheExtension, registerCacheLoader, registerCacheWriter, registerDynamicAttributesExtractor, releaseReadLockOnKey, releaseWriteLockOnKey, removeAll, removeAll, removePropertyChangeListener, setBootstrapCacheLoader, setCacheExceptionHandler, setCacheManager, setDisabled, setName, setNodeBulkLoadEnabled, setNodeCoherent, setTransactionManagerLookup, toString, tryReadLockOnKey, tryWriteLockOnKey, unregisterCacheExtension, unregisterCacheLoader, unregisterCacheWriter, waitUntilClusterBulkLoadComplete, waitUntilClusterCoherent
-
-
-
-
Constructor Detail
-
StronglyConsistentCacheAccessor
public StronglyConsistentCacheAccessor(Ehcache underlyingCache) throws java.lang.IllegalArgumentException
Constructor accepting the cache to be decorated.- Parameters:
underlyingCache- a clustered cache configured with eventual consistency- Throws:
java.lang.IllegalArgumentException- if the underlying cache is not clustered and has not eventual consistency.
-
-
Method Detail
-
putIfAbsent
public Element putIfAbsent(Element element, boolean doNotNotifyCacheReplicators) throws java.lang.NullPointerException
Description copied from interface:EhcachePut an element in the cache if no element is currently mapped to the elements key.- Specified by:
putIfAbsentin interfaceEhcache- Overrides:
putIfAbsentin classEhcacheDecoratorAdapter- Parameters:
element- element to be addeddoNotNotifyCacheReplicators- whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a further notification to doNotNotifyCacheReplicators cache peers- Returns:
- the element previously cached for this key, or null if none.
- Throws:
java.lang.NullPointerException- if the element is null, or has a null key
-
putIfAbsent
public Element putIfAbsent(Element element) throws java.lang.NullPointerException
Description copied from class:EhcacheDecoratorAdapterPut an element in the cache if no element is currently mapped to the elements key.- Specified by:
putIfAbsentin interfaceEhcache- Overrides:
putIfAbsentin classEhcacheDecoratorAdapter- Parameters:
element- element to be added- Returns:
- the element previously cached for this key, or null if none.
- Throws:
java.lang.NullPointerException- if the element is null, or has a null key
-
replace
public boolean replace(Element old, Element element) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
Description copied from class:EhcacheDecoratorAdapterReplace the cached element only if the current Element is equal to the supplied old Element.- Specified by:
replacein interfaceEhcache- Overrides:
replacein classEhcacheDecoratorAdapter- Parameters:
old- Element to be test againstelement- Element to be cached- Returns:
- true if the Element was replaced
- Throws:
java.lang.NullPointerException- if the either Element is null or has a null keyjava.lang.IllegalArgumentException- if the two Element keys are non-null but not equal
-
replace
public Element replace(Element element) throws java.lang.NullPointerException
Description copied from class:EhcacheDecoratorAdapterReplace the cached element only if an Element is currently cached for this key- Specified by:
replacein interfaceEhcache- Overrides:
replacein classEhcacheDecoratorAdapter- Parameters:
element- Element to be cached- Returns:
- the Element previously cached for this key, or null if no Element was cached
- Throws:
java.lang.NullPointerException- if the Element is null or has a null key
-
removeElement
public boolean removeElement(Element element) throws java.lang.NullPointerException
Description copied from class:EhcacheDecoratorAdapterRemove the Element mapped to the key for the supplied element if the value of the supplied Element compares equal to the value of the cached Element.This is equivalent to
if (elementValueComparator.equals(cache.get(element.getObjectKey()), element)) { return cache.remove(element.getObjectKey()); } else return false;except that the action is performed atomically.- Specified by:
removeElementin interfaceEhcache- Overrides:
removeElementin classEhcacheDecoratorAdapter- Parameters:
element- Element to be removed- Returns:
trueif the value was removed- Throws:
java.lang.NullPointerException- if the element is null, or has a null key- See Also:
CacheConfiguration.addElementValueComparator(net.sf.ehcache.config.ElementValueComparatorConfiguration)
-
put
public void put(Element element, boolean doNotNotifyCacheReplicators) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterPut an element in the cache.Resets the access statistics on the element, which would be the case if it has previously been gotten from a cache, and is now being put back.
Also notifies the CacheEventListener that:
- the element was put, but only if the Element was actually put.
- if the element exists in the cache, that an update has occurred, even if the element would be expired if it was requested
- Specified by:
putin interfaceEhcache- Overrides:
putin classEhcacheDecoratorAdapter- Parameters:
element- An object. If Serializable it can fully participate in replication and the DiskStore.doNotNotifyCacheReplicators- whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a further notification to doNotNotifyCacheReplicators cache peers- Throws:
java.lang.IllegalArgumentException- if the element is nulljava.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException
-
put
public void put(Element element) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterPut an element in the cache.Resets the access statistics on the element, which would be the case if it has previously been gotten from a cache, and is now being put back.
Also notifies the CacheEventListener that:
- the element was put, but only if the Element was actually put.
- if the element exists in the cache, that an update has occurred, even if the element would be expired if it was requested
- Specified by:
putin interfaceEhcache- Overrides:
putin classEhcacheDecoratorAdapter- Parameters:
element- An object. If Serializable it can fully participate in replication and the DiskStore.- Throws:
java.lang.IllegalArgumentException- if the element is nulljava.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException- a runtime cache exception
-
putAll
public void putAll(java.util.Collection<Element> elements) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterPuts a collection of elements in to the cache.This method will throw a
NullPointerExceptionif a null element or null key is encountered in the collection, and a partial completion may result (as only some of the elements may have been put).For each element that is put the registered
CacheEventListeners are notified of a newly put item (notifyElementPut(...)) regardless of whether the individual put is a new put or an update.- Specified by:
putAllin interfaceEhcache- Overrides:
putAllin classEhcacheDecoratorAdapter- Parameters:
elements- the collection of elements to be put in the cache.- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException- a runtime cache exceptionjava.lang.IllegalArgumentException
-
putQuiet
public void putQuiet(Element element) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterPut an element in the cache, without updating statistics, or updating listeners. This is meant to be used in conjunction withEhcache.getQuiet(java.io.Serializable)- Specified by:
putQuietin interfaceEhcache- Overrides:
putQuietin classEhcacheDecoratorAdapter- Parameters:
element- An object. If Serializable it can fully participate in replication and the DiskStore.- Throws:
java.lang.IllegalArgumentException- if the element is nulljava.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException
-
putWithWriter
public void putWithWriter(Element element) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterPut an element in the cache writing through a CacheWriter. If no CacheWriter has been registered for the cache, then this method throws an exception.Resets the access statistics on the element, which would be the case if it has previously been gotten from a cache, and is now being put back.
Also notifies the CacheEventListener, if the writer operation succeeds, that:
- the element was put, but only if the Element was actually put.
- if the element exists in the cache, that an update has occurred, even if the element would be expired if it was requested
- Specified by:
putWithWriterin interfaceEhcache- Overrides:
putWithWriterin classEhcacheDecoratorAdapter- Parameters:
element- An object. If Serializable it can fully participate in replication and the DiskStore.- Throws:
java.lang.IllegalArgumentException- if the element is nulljava.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException- if no CacheWriter was registered
-
remove
public boolean remove(java.lang.Object key, boolean doNotNotifyCacheReplicators) throws java.lang.IllegalStateExceptionDescription copied from class:EhcacheDecoratorAdapterRemoves anElementfrom the Cache. This also removes it from any stores it may be in.Also notifies the CacheEventListener after the element was removed, but only if an Element with the key actually existed.
- Specified by:
removein interfaceEhcache- Overrides:
removein classEhcacheDecoratorAdapter- Parameters:
key- of the element to removedoNotNotifyCacheReplicators- whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a further notification to doNotNotifyCacheReplicators cache peers- Returns:
- true if the element was removed, false if it was not found in the cache
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
removeAll
public void removeAll(java.util.Collection<?> keys) throws java.lang.IllegalStateExceptionDescription copied from class:EhcacheDecoratorAdapterRemoves given set ofElementfrom the Cache. This also removes them from any stores it may be in. Throws a NullPointerException if any key in the collection is nullAlso notifies the CacheEventListener after the elements were removed. Notification is sent for every key irrespective of whether the key was present in the cache or not This operation is partially completed if any element or any key is null
- Specified by:
removeAllin interfaceEhcache- Overrides:
removeAllin classEhcacheDecoratorAdapter- Parameters:
keys- a collection of keys to operate on- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
remove
public boolean remove(java.lang.Object key) throws java.lang.IllegalStateExceptionDescription copied from class:EhcacheDecoratorAdapterRemoves anElementfrom the Cache. This also removes it from any stores it may be in.Also notifies the CacheEventListener after the element was removed, but only if an Element with the key actually existed.
- Specified by:
removein interfaceEhcache- Overrides:
removein classEhcacheDecoratorAdapter- Parameters:
key- the key of the element to remove- Returns:
- true if the element was removed, false if it was not found in the cache
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
removeAll
public void removeAll(java.util.Collection<?> keys, boolean doNotNotifyCacheReplicators) throws java.lang.IllegalStateExceptionDescription copied from class:EhcacheDecoratorAdapterRemoves all cached items.When using Terracotta clustered caches with nonstop enabled, the timeout used by this method is
NonstopConfiguration.getBulkOpsTimeoutMultiplyFactor()times the timeout value in the nonstop config.- Specified by:
removeAllin interfaceEhcache- Overrides:
removeAllin classEhcacheDecoratorAdapter- Parameters:
keys- a collection of keys to operate ondoNotNotifyCacheReplicators- whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a further notification to doNotNotifyCacheReplicators cache peers- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
remove
public boolean remove(java.io.Serializable key, boolean doNotNotifyCacheReplicators) throws java.lang.IllegalStateExceptionDescription copied from class:EhcacheDecoratorAdapterRemoves anElementfrom the Cache. This also removes it from any stores it may be in.Also notifies the CacheEventListener after the element was removed, but only if an Element with the key actually existed.
- Specified by:
removein interfaceEhcache- Overrides:
removein classEhcacheDecoratorAdapter- Parameters:
key- the key of the element to removedoNotNotifyCacheReplicators- whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a further notification to doNotNotifyCacheReplicators cache peers- Returns:
- true if the element was removed, false if it was not found in the cache
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
remove
public boolean remove(java.io.Serializable key) throws java.lang.IllegalStateExceptionDescription copied from class:EhcacheDecoratorAdapterRemoves anElementfrom the Cache. This also removes it from any stores it may be in.Also notifies the CacheEventListener after the element was removed.
- Specified by:
removein interfaceEhcache- Overrides:
removein classEhcacheDecoratorAdapter- Parameters:
key- the key of the element to remove- Returns:
- true if the element was removed, false if it was not found in the cache
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
removeQuiet
public boolean removeQuiet(java.lang.Object key) throws java.lang.IllegalStateExceptionDescription copied from class:EhcacheDecoratorAdapterRemoves anElementfrom the Cache, without notifying listeners. This also removes it from any stores it may be in.- Specified by:
removeQuietin interfaceEhcache- Overrides:
removeQuietin classEhcacheDecoratorAdapter- Parameters:
key- of the element to remove- Returns:
- true if the element was removed, false if it was not found in the cache
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
removeQuiet
public boolean removeQuiet(java.io.Serializable key) throws java.lang.IllegalStateExceptionDescription copied from class:EhcacheDecoratorAdapterRemoves anElementfrom the Cache, without notifying listeners. This also removes it from any stores it may be in.- Specified by:
removeQuietin interfaceEhcache- Overrides:
removeQuietin classEhcacheDecoratorAdapter- Parameters:
key- of the element to remove- Returns:
- true if the element was removed, false if it was not found in the cache
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
removeWithWriter
public boolean removeWithWriter(java.lang.Object key) throws java.lang.IllegalStateException, CacheExceptionDescription copied from class:EhcacheDecoratorAdapterRemoves anElementfrom the Cache and any stores it might be in. This also removes through to a CacheWriter. If no CacheWriter has been registered for the cache, then this method throws an exception.Also notifies the CacheEventListener after the element was removed, but only if an Element with the key actually existed.
- Specified by:
removeWithWriterin interfaceEhcache- Overrides:
removeWithWriterin classEhcacheDecoratorAdapter- Parameters:
key- of the element to remove- Returns:
- true if the element was removed, false if it was not found in the cache
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException- if no CacheWriter was registered
-
removeAndReturnElement
public Element removeAndReturnElement(java.lang.Object key) throws java.lang.IllegalStateException
Description copied from class:EhcacheDecoratorAdapterRemoves and returns the element associated with the key- Specified by:
removeAndReturnElementin interfaceInternalEhcache- Overrides:
removeAndReturnElementin classEhcacheDecoratorAdapter- Parameters:
key- the key of the element to operate on- Returns:
- element the removed element associated with the key, null if no mapping exists
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
get
public Element get(java.lang.Object key) throws java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterGets an element from the cache. Updates Element StatisticsNote that the Element's lastAccessTime is always the time of this get. Use
Ehcache.getQuiet(Object)to peek into the Element to see its last access time with get- Specified by:
getin interfaceEhcache- Overrides:
getin classEhcacheDecoratorAdapter- Parameters:
key- an Object value- Returns:
- the element, or null, if it does not exist.
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException- See Also:
Ehcache.isExpired(net.sf.ehcache.Element)
-
getAll
public java.util.Map<java.lang.Object,Element> getAll(java.util.Collection<?> keys) throws java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterGets all the elements from the cache for the keys provided. Updates Element Statistics Throws a NullPointerException if any key in the collection is nullNote that the Element's lastAccessTime is always the time of this get. Use
Ehcache.getQuiet(Object)to peek into the Element to see its last access time with get- Specified by:
getAllin interfaceEhcache- Overrides:
getAllin classEhcacheDecoratorAdapter- Parameters:
keys- a collection of keys for which value is to be fetched- Returns:
- Map of key and elements for the provided keys, value will be null for the keys which do not exist
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException- See Also:
Ehcache.isExpired(net.sf.ehcache.Element)
-
get
public Element get(java.io.Serializable key) throws java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterGets an element from the cache. Updates Element StatisticsNote that the Element's lastAccessTime is always the time of this get. Use
Ehcache.getQuiet(Object)to peak into the Element to see its last access time with get- Specified by:
getin interfaceEhcache- Overrides:
getin classEhcacheDecoratorAdapter- Parameters:
key- a serializable value- Returns:
- the element, or null, if it does not exist.
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException- See Also:
Ehcache.isExpired(net.sf.ehcache.Element)
-
getQuiet
public Element getQuiet(java.lang.Object key) throws java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterGets an element from the cache, without updating Element statistics. Cache statistics are also not updated.- Specified by:
getQuietin interfaceEhcache- Overrides:
getQuietin classEhcacheDecoratorAdapter- Parameters:
key- a serializable value- Returns:
- the element, or null, if it does not exist.
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException- See Also:
Ehcache.isExpired(net.sf.ehcache.Element)
-
getQuiet
public Element getQuiet(java.io.Serializable key) throws java.lang.IllegalStateException, CacheException
Description copied from class:EhcacheDecoratorAdapterGets an element from the cache, without updating Element statistics. Cache statistics are still updated.- Specified by:
getQuietin interfaceEhcache- Overrides:
getQuietin classEhcacheDecoratorAdapter- Parameters:
key- a serializable value- Returns:
- the element, or null, if it does not exist.
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException- See Also:
Ehcache.isExpired(net.sf.ehcache.Element)
-
getWithLoader
public Element getWithLoader(java.lang.Object key, CacheLoader loader, java.lang.Object loaderArgument) throws CacheException
Description copied from class:EhcacheDecoratorAdapterThis method will return, from the cache, the object associated with the argument "key".If the object is not in the cache, the associated cache loader will be called. That is either the CacheLoader passed in, or if null, the one associated with the cache. If both are null, no load is performed and null is returned.
Because this method may take a long time to complete, it is not synchronized. The underlying cache operations are synchronized.
- Specified by:
getWithLoaderin interfaceEhcache- Overrides:
getWithLoaderin classEhcacheDecoratorAdapter- Parameters:
key- key whose associated value is to be returned.loader- the override loader to use. If null, the cache's default loader will be usedloaderArgument- an argument to pass to the CacheLoader.- Returns:
- an element if it existed or could be loaded, otherwise null
- Throws:
CacheException- a runtime cache exception
-
getAllWithLoader
public java.util.Map getAllWithLoader(java.util.Collection keys, java.lang.Object loaderArgument) throws CacheExceptionDescription copied from class:EhcacheDecoratorAdapterThe getAll method will return, from the cache, a Map of the objects associated with the Collection of keys in argument "keys". If the objects are not in the cache, the associated cache loader will be called. If no loader is associated with an object, a null is returned. If a problem is encountered during the retrieving or loading of the objects, an exception will be thrown. If the "arg" argument is set, the arg object will be passed to the CacheLoader.loadAll method. The cache will not dereference the object. If no "arg" value is provided a null will be passed to the loadAll method. The storing of null values in the cache is permitted, however, the get method will not distinguish returning a null stored in the cache and not finding the object in the cache. In both cases a null is returned.Note. If the getAll exceeds the maximum cache size, the returned map will necessarily be less than the number specified.
Because this method may take a long time to complete, it is not synchronized. The underlying cache operations are synchronized.
The constructs package provides similar functionality using the decorator
SelfPopulatingCache- Specified by:
getAllWithLoaderin interfaceEhcache- Overrides:
getAllWithLoaderin classEhcacheDecoratorAdapter- Parameters:
keys- a collection of keys to be returned/loadedloaderArgument- an argument to pass to the CacheLoader.- Returns:
- a Map populated from the Cache. If there are no elements, an empty Map is returned.
- Throws:
CacheException- a runtime cache exception
-
-