ehcache

net.sf.ehcache.constructs
Class EhcacheDecoratorAdapter

java.lang.Object
  extended by net.sf.ehcache.constructs.EhcacheDecoratorAdapter
All Implemented Interfaces:
Cloneable, Ehcache, InternalEhcache
Direct Known Subclasses:
BlockingCache, ReadThroughCache, RefreshAheadCache, StronglyConsistentCacheAccessor

public class EhcacheDecoratorAdapter
extends Object
implements InternalEhcache

Adapter class for Ehcache interface decorators. Implements all method in Ehcache by delegating all calls to the decorated Ehcache. This class is provided as a convenience for easily creating Ehcache decorators by extending this class and overriding only the methods of interest.

Author:
Abhishek Sanoujam

Field Summary
protected  Ehcache underlyingCache
          The decorated Ehcache, has protected visibility so that sub-classes can have access to it.
 
Constructor Summary
EhcacheDecoratorAdapter(Ehcache underlyingCache)
          Constructor accepting the cache to be decorated
 
Method Summary
 void acquireReadLockOnKey(Object key)
          Acquires the proper read lock for a given cache key
 void acquireWriteLockOnKey(Object key)
          Acquires the proper write lock for a given cache key
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add a PropertyChangeListener.
 void bootstrap()
          Bootstrap command.
 long calculateInMemorySize()
          Deprecated. 
 long calculateOffHeapSize()
          Deprecated. 
 long calculateOnDiskSize()
          Deprecated. 
 Object clone()
          Clones a cache.
 Query createQuery()
          Create a new query builder for this cache
 void disableDynamicFeatures()
          Disables dynamic configuration and disable/enable for this cache.
 void dispose()
          Flushes all cache items from memory to auxilliary caches and close the auxilliary caches.
 void evictExpiredElements()
          Causes all elements stored in the Cache to be synchronously checked for expiry, and if expired, evicted.
 void flush()
          Flushes all cache items from memory to the disk store, and from the DiskStore to disk.
 Element get(Object key)
          Gets an element from the cache.
 Element get(Serializable key)
          Gets an element from the cache.
 Map<Object,Element> getAll(Collection<?> keys)
          Gets all the elements from the cache for the keys provided.
 Map getAllWithLoader(Collection keys, Object loaderArgument)
          The getAll method will return, from the cache, a Map of the objects associated with the Collection of keys in argument "keys".
 BootstrapCacheLoader getBootstrapCacheLoader()
          Accessor for the BootstrapCacheLoader associated with this cache.
 CacheConfiguration getCacheConfiguration()
          Gets the cache configuration this cache was created with.
 RegisteredEventListeners getCacheEventNotificationService()
          Use this to access the service in order to register and unregister listeners
 CacheExceptionHandler getCacheExceptionHandler()
          Sets an ExceptionHandler on the Cache.
 CacheManager getCacheManager()
          Gets the CacheManager managing this cache.
 int getDiskStoreSize()
          Deprecated. 
 String getGuid()
          The GUID for this cache instance can be used to determine whether two cache instance references are pointing to the same cache.
 Object getInternalContext()
          This should not be used return some internal context (generally will be null)
 List getKeys()
          Returns a list of all elements in the cache, whether or not they are expired.
 List getKeysNoDuplicateCheck()
          Returns a list of all elements in the cache, whether or not they are expired.
 List getKeysWithExpiryCheck()
          Returns a list of all elements in the cache.
 long getMemoryStoreSize()
          Deprecated. 
 String getName()
          Gets the cache name.
 long getOffHeapStoreSize()
          Deprecated. 
 Element getQuiet(Object key)
          Gets an element from the cache, without updating Element statistics.
 Element getQuiet(Serializable key)
          Gets an element from the cache, without updating Element statistics.
 List<CacheExtension> getRegisteredCacheExtensions()
          
 List<CacheLoader> getRegisteredCacheLoaders()
          
 CacheWriter getRegisteredCacheWriter()
          Retrieves the CacheWriter that was registered for this cache.
<T> Attribute<T>
getSearchAttribute(String attributeName)
          Retrieve the given named search attribute
 Set<Attribute> getSearchAttributes()
           
 int getSize()
          Gets the size of the cache.
 StatisticsGateway getStatistics()
          Gets an immutable Statistics object representing the Cache statistics at the time.
 Status getStatus()
          Gets the status attribute of the Cache.
 Element getWithLoader(Object key, CacheLoader loader, Object loaderArgument)
          This method will return, from the cache, the object associated with the argument "key".
 CacheWriterManager getWriterManager()
          Obtain the writer manager that's used by this cache instance.
 boolean hasAbortedSizeOf()
          Check if the cache may contain elements which the SizeOf engine could not fully size.
 void initialise()
          Newly created caches do not have a MemoryStore or a DiskStore.
 boolean isClusterBulkLoadEnabled()
          Returns true if at least one node in the cluster is in bulk-load mode.
 boolean isClusterCoherent()
          Deprecated. Use isClusterBulkLoadEnabled() instead
 boolean isDisabled()
          Whether this cache is disabled.
 boolean isElementInMemory(Object key)
          Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval.
 boolean isElementInMemory(Serializable key)
          Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval.
 boolean isElementOnDisk(Object key)
          Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval.
 boolean isElementOnDisk(Serializable key)
          Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval.
 boolean isExpired(Element element)
          Checks whether this cache element has expired.
 boolean isKeyInCache(Object key)
          An inexpensive check to see if the key exists in the cache.
 boolean isNodeBulkLoadEnabled()
          Returns true if the current node is in bulk-load mode.
 boolean isNodeCoherent()
          Deprecated. Use isNodeBulkLoadEnabled() instead
 boolean isReadLockedByCurrentThread(Object key)
          Returns true if a read lock for the key is held by the current thread
 boolean isSearchable()
          Is this cache searchable?
 boolean isValueInCache(Object value)
          An extremely expensive check to see if the value exists in the cache.
 boolean isWriteLockedByCurrentThread(Object key)
          Returns true if a write lock for the key is held by the current thread
 void load(Object key)
          The load method provides a means to "pre load" the cache.
 void loadAll(Collection keys, Object argument)
          The loadAll method provides a means to "pre load" objects into the cache.
 void put(Element element)
          Put an element in the cache.
 void put(Element element, boolean doNotNotifyCacheReplicators)
          Put an element in the cache.
 void putAll(Collection<Element> elements)
          Puts a collection of elements in to the cache.
 Element putIfAbsent(Element element)
          Put an element in the cache if no element is currently mapped to the elements key.
 Element putIfAbsent(Element element, boolean doNotNotifyCacheReplicators)
          Put an element in the cache if no element is currently mapped to the elements key.
 void putQuiet(Element element)
          Put an element in the cache, without updating statistics, or updating listeners.
 void putWithWriter(Element element)
          Put an element in the cache writing through a CacheWriter.
 void recalculateSize(Object key)
          Recalculate the size of the element mapped to the key
 void registerCacheExtension(CacheExtension cacheExtension)
          Register a CacheExtension with the cache.
 void registerCacheLoader(CacheLoader cacheLoader)
          Register a CacheLoader with the cache.
 void registerCacheWriter(CacheWriter cacheWriter)
          Register the CacheWriter for this cache.
 void registerDynamicAttributesExtractor(DynamicAttributesExtractor extractor)
          Allows user to register a dynamic attribute extractor with a searchable cache that is dynamically indexable, as indicated by its configuration.
 void releaseReadLockOnKey(Object key)
          Release a held read lock for the passed in key
 void releaseWriteLockOnKey(Object key)
          Release a held write lock for the passed in key
 boolean remove(Object key)
          Removes an Element from the Cache.
 boolean remove(Object key, boolean doNotNotifyCacheReplicators)
          Removes an Element from the Cache.
 boolean remove(Serializable key)
          Removes an Element from the Cache.
 boolean remove(Serializable key, boolean doNotNotifyCacheReplicators)
          Removes an Element from the Cache.
 void removeAll()
          Removes all cached items.
 void removeAll(boolean doNotNotifyCacheReplicators)
          Removes all cached items.
 void removeAll(Collection<?> keys)
          Removes given set of Element from the Cache.
 void removeAll(Collection<?> keys, boolean doNotNotifyCacheReplicators)
          Removes all cached items.
 Element removeAndReturnElement(Object key)
          Removes and returns the element associated with the key
 boolean removeElement(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.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a PropertyChangeListener.
 boolean removeQuiet(Object key)
          Removes an Element from the Cache, without notifying listeners.
 boolean removeQuiet(Serializable key)
          Removes an Element from the Cache, without notifying listeners.
 boolean removeWithWriter(Object key)
          Removes an Element from the Cache and any stores it might be in.
 Element replace(Element element)
          Replace the cached element only if an Element is currently cached for this key
 boolean replace(Element old, Element element)
          Replace the cached element only if the current Element is equal to the supplied old Element.
 void setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader)
          Sets the bootstrap cache loader.
 void setCacheExceptionHandler(CacheExceptionHandler cacheExceptionHandler)
          Sets an ExceptionHandler on the Cache.
 void setCacheManager(CacheManager cacheManager)
          Sets the CacheManager
 void setDisabled(boolean disabled)
          Disables or enables this cache.
 void setName(String name)
          Sets the cache name which will name.
 void setNodeBulkLoadEnabled(boolean enabledBulkLoad)
          Enable/disable bulk-load mode in this node for this cache.
 void setNodeCoherent(boolean coherent)
          Deprecated. Use setNodeBulkLoadEnabled(boolean) instead
 void setTransactionManagerLookup(TransactionManagerLookup transactionManagerLookup)
          This class is used to access the transaction manager used during XA.
 String toString()
          Returns a String representation of Cache.
 boolean tryReadLockOnKey(Object key, long timeout)
          Try to get a read lock on a given key.
 boolean tryWriteLockOnKey(Object key, long timeout)
          Try to get a write lock on a given key.
 void unregisterCacheExtension(CacheExtension cacheExtension)
          Unregister a CacheExtension with the cache.
 void unregisterCacheLoader(CacheLoader cacheLoader)
          Unregister a CacheLoader with the cache.
 void unregisterCacheWriter()
          Unregister the CacheWriter from the cache.
 void waitUntilClusterBulkLoadComplete()
          This method waits until all the connected nodes have disabled bulk-load.
 void waitUntilClusterCoherent()
          Deprecated. Use waitUntilClusterBulkLoadComplete() instead
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

underlyingCache

protected final Ehcache underlyingCache
The decorated Ehcache, has protected visibility so that sub-classes can have access to it.

Constructor Detail

EhcacheDecoratorAdapter

public EhcacheDecoratorAdapter(Ehcache underlyingCache)
Constructor accepting the cache to be decorated

Parameters:
underlyingCache -
Method Detail

get

public Element get(Object key)
            throws IllegalStateException,
                   CacheException
Gets an element from the cache. Updates Element Statistics

Note 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:
get in interface Ehcache
Parameters:
key - an Object value
Returns:
the element, or null, if it does not exist.
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
See Also:
Ehcache.isExpired(net.sf.ehcache.Element)

getAll

public Map<Object,Element> getAll(Collection<?> keys)
                           throws IllegalStateException,
                                  CacheException
Gets all the elements from the cache for the keys provided. Updates Element Statistics Throws a NullPointerException if any key in the collection is null

Note 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:
getAll in interface Ehcache
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:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
See Also:
Ehcache.isExpired(net.sf.ehcache.Element)

get

public Element get(Serializable key)
            throws IllegalStateException,
                   CacheException
Gets an element from the cache. Updates Element Statistics

Note 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:
get in interface Ehcache
Parameters:
key - a serializable value
Returns:
the element, or null, if it does not exist.
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
See Also:
Ehcache.isExpired(net.sf.ehcache.Element)

getQuiet

public Element getQuiet(Object key)
                 throws IllegalStateException,
                        CacheException
Gets an element from the cache, without updating Element statistics. Cache statistics are also not updated.

Specified by:
getQuiet in interface Ehcache
Parameters:
key - a serializable value
Returns:
the element, or null, if it does not exist.
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
See Also:
Ehcache.isExpired(net.sf.ehcache.Element)

getQuiet

public Element getQuiet(Serializable key)
                 throws IllegalStateException,
                        CacheException
Gets an element from the cache, without updating Element statistics. Cache statistics are still updated.

Specified by:
getQuiet in interface Ehcache
Parameters:
key - a serializable value
Returns:
the element, or null, if it does not exist.
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
See Also:
Ehcache.isExpired(net.sf.ehcache.Element)

put

public void put(Element element,
                boolean doNotNotifyCacheReplicators)
         throws IllegalArgumentException,
                IllegalStateException,
                CacheException
Put 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:

Specified by:
put in interface Ehcache
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:
IllegalArgumentException - if the element is null
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException

put

public void put(Element element)
         throws IllegalArgumentException,
                IllegalStateException,
                CacheException
Put 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:

Specified by:
put in interface Ehcache
Parameters:
element - An object. If Serializable it can fully participate in replication and the DiskStore.
Throws:
IllegalArgumentException - if the element is null
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException

putAll

public void putAll(Collection<Element> elements)
            throws IllegalArgumentException,
                   IllegalStateException,
                   CacheException
Puts a collection of elements in to the cache.

This method will throw a NullPointerException if 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:
putAll in interface Ehcache
Parameters:
elements - the collection of elements to be put in the cache.
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
IllegalArgumentException

putQuiet

public void putQuiet(Element element)
              throws IllegalArgumentException,
                     IllegalStateException,
                     CacheException
Put an element in the cache, without updating statistics, or updating listeners. This is meant to be used in conjunction with Ehcache.getQuiet(java.io.Serializable)

Specified by:
putQuiet in interface Ehcache
Parameters:
element - An object. If Serializable it can fully participate in replication and the DiskStore.
Throws:
IllegalArgumentException - if the element is null
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException

putWithWriter

public void putWithWriter(Element element)
                   throws IllegalArgumentException,
                          IllegalStateException,
                          CacheException
Put 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:

Specified by:
putWithWriter in interface Ehcache
Parameters:
element - An object. If Serializable it can fully participate in replication and the DiskStore.
Throws:
IllegalArgumentException - if the element is null
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException - if no CacheWriter was registered

remove

public boolean remove(Object key,
                      boolean doNotNotifyCacheReplicators)
               throws IllegalStateException
Removes an Element from 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:
remove in interface Ehcache
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
Returns:
true if the element was removed, false if it was not found in the cache
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

remove

public boolean remove(Object key)
               throws IllegalStateException
Removes an Element from 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:
remove in interface Ehcache
Returns:
true if the element was removed, false if it was not found in the cache
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

removeAll

public void removeAll(Collection<?> keys)
               throws IllegalStateException
Removes given set of Element from the Cache. This also removes them from any stores it may be in. Throws a NullPointerException if any key in the collection is null

Also 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:
removeAll in interface Ehcache
Parameters:
keys - a collection of keys to operate on
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

removeAll

public void removeAll(Collection<?> keys,
                      boolean doNotNotifyCacheReplicators)
               throws IllegalStateException
Removes 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:
removeAll in interface Ehcache
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:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

remove

public boolean remove(Serializable key,
                      boolean doNotNotifyCacheReplicators)
               throws IllegalStateException
Removes an Element from 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:
remove in interface Ehcache
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
Returns:
true if the element was removed, false if it was not found in the cache
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

remove

public boolean remove(Serializable key)
               throws IllegalStateException
Removes an Element from the Cache. This also removes it from any stores it may be in.

Also notifies the CacheEventListener after the element was removed.

Specified by:
remove in interface Ehcache
Returns:
true if the element was removed, false if it was not found in the cache
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

removeAll

public void removeAll()
               throws IllegalStateException,
                      CacheException
Removes 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:
removeAll in interface Ehcache
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException

removeAll

public void removeAll(boolean doNotNotifyCacheReplicators)
               throws IllegalStateException,
                      CacheException
Removes 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:
removeAll in interface Ehcache
Parameters:
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:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException

bootstrap

public void bootstrap()
Bootstrap command. This must be called after the Cache is intialised, during CacheManager initialisation. If loads are synchronous, they will complete before the CacheManager initialise completes, otherwise they will happen in the background.

This method is not intended to be called explicitly, but rather is called implicitly by the cache's CacheManager instance during the cache initialization. Invoking this method directly will likely lead to breaking.

Specified by:
bootstrap in interface Ehcache

calculateInMemorySize

@Deprecated
public long calculateInMemorySize()
                           throws IllegalStateException,
                                  CacheException
Deprecated. 

Gets the size of the memory store for this cache

Warning: This method can be very expensive to run. Allow approximately 1 second per 1MB of entries. Running this method could create liveness problems because the object lock is held for a long period

Specified by:
calculateInMemorySize in interface Ehcache
Returns:
the approximate size of the memory store in bytes
Throws:
IllegalStateException
CacheException

calculateOffHeapSize

@Deprecated
public long calculateOffHeapSize()
                          throws IllegalStateException,
                                 CacheException
Deprecated. 

Gets the size of the off-heap store for this cache

Specified by:
calculateOffHeapSize in interface Ehcache
Returns:
the size of the off-heap store in bytes
Throws:
IllegalStateException
CacheException

calculateOnDiskSize

@Deprecated
public long calculateOnDiskSize()
                         throws IllegalStateException,
                                CacheException
Deprecated. 

Gets the size of the on-disk store for this cache

Specified by:
calculateOnDiskSize in interface Ehcache
Returns:
the size of the on-disk store in bytes
Throws:
IllegalStateException
CacheException

hasAbortedSizeOf

public boolean hasAbortedSizeOf()
Check if the cache may contain elements which the SizeOf engine could not fully size.

Specified by:
hasAbortedSizeOf in interface Ehcache
Returns:
true if the cache may contain partially sized objects

disableDynamicFeatures

public void disableDynamicFeatures()
Disables dynamic configuration and disable/enable for this cache.

This is a one time operation. Once an Ehcache instance has had its dynamic operations disabled they cannot be re-enabled.

Specified by:
disableDynamicFeatures in interface Ehcache

dispose

public void dispose()
             throws IllegalStateException
Flushes all cache items from memory to auxilliary caches and close the auxilliary caches.

Should be invoked only by CacheManager.

Specified by:
dispose in interface Ehcache
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

evictExpiredElements

public void evictExpiredElements()
Causes all elements stored in the Cache to be synchronously checked for expiry, and if expired, evicted.

For large caches - or caches with high-latency storage this method can take a very long time to complete. You should seriously consider relying on some form of capacity eviction to control cache capacity over calling this method. As this method can take a long time the cache may not be fully purged of expired elements on return, since more elements may have expired during the call.

Specified by:
evictExpiredElements in interface Ehcache

flush

public void flush()
           throws IllegalStateException,
                  CacheException
Flushes all cache items from memory to the disk store, and from the DiskStore to disk.

Specified by:
flush in interface Ehcache
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException

getWithLoader

public Element getWithLoader(Object key,
                             CacheLoader loader,
                             Object loaderArgument)
                      throws CacheException
This 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:
getWithLoader in interface Ehcache
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 used
loaderArgument - an argument to pass to the CacheLoader.
Returns:
an element if it existed or could be loaded, otherwise null
Throws:
CacheException

getAllWithLoader

public Map getAllWithLoader(Collection keys,
                            Object loaderArgument)
                     throws CacheException
The 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:
getAllWithLoader in interface Ehcache
Parameters:
keys - a collection of keys to be returned/loaded
loaderArgument - 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

registerCacheLoader

public void registerCacheLoader(CacheLoader cacheLoader)
Register a CacheLoader with the cache. It will then be tied into the cache lifecycle.

The CacheLoader instance will be initialized when the cache itself is being initialized. Should the cache already be initialized, CacheLoader.init() will not be invoked. If the loader requires initialization, the user will have to call it manually before registering it with a Cache instance that's already alive

Specified by:
registerCacheLoader in interface Ehcache
Parameters:
cacheLoader - A Cache Loader to register

unregisterCacheLoader

public void unregisterCacheLoader(CacheLoader cacheLoader)
Unregister a CacheLoader with the cache. It will then be detached from the cache lifecycle.

Specified by:
unregisterCacheLoader in interface Ehcache
Parameters:
cacheLoader - A Cache Loader to unregister

load

public void load(Object key)
          throws CacheException
The load method provides a means to "pre load" the cache. This method will, asynchronously, load the specified object into the cache using the associated cacheloader. If the object already exists in the cache, no action is taken. If no loader is associated with the object, no object will be loaded into the cache. If a problem is encountered during the retrieving or loading of the object, an exception should be logged. If the "arg" argument is set, the arg object will be passed to the CacheLoader.load method. The cache will not dereference the object. If no "arg" value is provided a null will be passed to the load 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.

The Ehcache native API provides similar functionality to loaders using the decorator SelfPopulatingCache

Specified by:
load in interface Ehcache
Parameters:
key - key whose associated value to be loaded using the associated cacheloader if this cache doesn't contain it.
Throws:
CacheException

loadAll

public void loadAll(Collection keys,
                    Object argument)
             throws CacheException
The loadAll method provides a means to "pre load" objects into the cache. This method will, asynchronously, load the specified objects into the cache using the associated cache loader. If the an object already exists in the cache, no action is taken. If no loader is associated with the object, no object will be loaded into the cache. If a problem is encountered during the retrieving or loading of the objects, an exception (to be defined) should be logged. The 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 (to be defined) 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.

keys - collection of the keys whose associated values to be loaded into this cache by using the associated cacheloader if this cache doesn't contain them.

The Ehcache native API provides similar functionality to loaders using the decorator SelfPopulatingCache

Specified by:
loadAll in interface Ehcache
Throws:
CacheException

getBootstrapCacheLoader

public BootstrapCacheLoader getBootstrapCacheLoader()
Accessor for the BootstrapCacheLoader associated with this cache. For testing purposes.

Specified by:
getBootstrapCacheLoader in interface Ehcache
Returns:
the BootstrapCacheLoader to use

getCacheConfiguration

public CacheConfiguration getCacheConfiguration()
Gets the cache configuration this cache was created with.

Things like listeners that are added dynamically are excluded.

Specified by:
getCacheConfiguration in interface Ehcache

getCacheEventNotificationService

public RegisteredEventListeners getCacheEventNotificationService()
Use this to access the service in order to register and unregister listeners

Specified by:
getCacheEventNotificationService in interface Ehcache
Returns:
the RegisteredEventListeners instance for this cache.

getCacheExceptionHandler

public CacheExceptionHandler getCacheExceptionHandler()
Sets an ExceptionHandler on the Cache. If one is already set, it is overwritten.

Specified by:
getCacheExceptionHandler in interface Ehcache

getCacheManager

public CacheManager getCacheManager()
Gets the CacheManager managing this cache. For a newly created cache this will be null until it has been added to a CacheManager.

Specified by:
getCacheManager in interface Ehcache
Returns:
the manager or null if there is none

getOffHeapStoreSize

@Deprecated
public long getOffHeapStoreSize()
                         throws IllegalStateException
Deprecated. 

Returns the number of elements in the off-heap store.

Specified by:
getOffHeapStoreSize in interface Ehcache
Returns:
the number of elements in the off-heap store
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

getDiskStoreSize

@Deprecated
public int getDiskStoreSize()
                     throws IllegalStateException
Deprecated. 

Returns the number of elements in the disk store.

Specified by:
getDiskStoreSize in interface Ehcache
Returns:
the number of elements in the disk store.
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

getGuid

public String getGuid()
The GUID for this cache instance can be used to determine whether two cache instance references are pointing to the same cache.

Specified by:
getGuid in interface Ehcache
Returns:
the globally unique identifier for this cache instance. This is guaranteed to be unique.

getInternalContext

public Object getInternalContext()
This should not be used return some internal context (generally will be null)

Specified by:
getInternalContext in interface Ehcache

getKeys

public List getKeys()
             throws IllegalStateException,
                    CacheException
Returns a list of all elements in the cache, whether or not they are expired.

The returned keys are unique and can be considered a set.

The List returned is not live. It is a copy.

The time taken is O(n). On a single cpu 1.8Ghz P4, approximately 8ms is required for each 1000 entries.

Specified by:
getKeys in interface Ehcache
Returns:
a list of Object keys
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException

getKeysNoDuplicateCheck

public List getKeysNoDuplicateCheck()
                             throws IllegalStateException
Returns a list of all elements in the cache, whether or not they are expired.

The returned keys are not unique and may contain duplicates. If the cache is only using the memory store, the list will be unique. If the disk store is being used as well, it will likely contain duplicates, because of the internal store design.

The List returned is not live. It is a copy.

The time taken is O(log n). On a single cpu 1.8Ghz P4, approximately 6ms is required for 1000 entries and 36 for 50000.

This is the fastest getKeys method

Specified by:
getKeysNoDuplicateCheck in interface Ehcache
Returns:
a list of Object keys
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

getKeysWithExpiryCheck

public List getKeysWithExpiryCheck()
                            throws IllegalStateException,
                                   CacheException
Returns a list of all elements in the cache. Only keys of non-expired elements are returned.

The returned keys are unique and can be considered a set.

The List returned is not live. It is a copy.

For large caches - or caches with high-latency storage this method can take a very long time to complete. You should seriously consider whether your usage requires checking for expired keys before choosing to call this method. As this method can take a long time the results may also be significantly out of date by the time the method returns.

Specified by:
getKeysWithExpiryCheck in interface Ehcache
Returns:
a list of Object keys
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException

getMemoryStoreSize

@Deprecated
public long getMemoryStoreSize()
                        throws IllegalStateException
Deprecated. 

Returns the number of elements in the memory store.

Specified by:
getMemoryStoreSize in interface Ehcache
Returns:
the number of elements in the memory store
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

getName

public String getName()
Gets the cache name.

Specified by:
getName in interface Ehcache

getRegisteredCacheExtensions

public List<CacheExtension> getRegisteredCacheExtensions()

Specified by:
getRegisteredCacheExtensions in interface Ehcache
Returns:
the cache extensions as a live list

getRegisteredCacheLoaders

public List<CacheLoader> getRegisteredCacheLoaders()

Specified by:
getRegisteredCacheLoaders in interface Ehcache
Returns:
the cache loaders as a live list

getRegisteredCacheWriter

public CacheWriter getRegisteredCacheWriter()
Retrieves the CacheWriter that was registered for this cache.

Specified by:
getRegisteredCacheWriter in interface Ehcache
Returns:
the registered CacheWriter; or null if none was registered before

getSize

public int getSize()
            throws IllegalStateException,
                   CacheException
Gets the size of the cache. This is a subtle concept. See below.

The size is the number of Elements in the MemoryStore plus the number of Elements in the DiskStore.

This number is the actual number of elements, including expired elements that have not been removed.

Expired elements are removed from the the memory store when getting an expired element, or when attempting to spool an expired element to disk.

Expired elements are removed from the disk store when getting an expired element, or when the expiry thread runs, which is once every five minutes.

To get an exact size, which would exclude expired elements, use Ehcache.getKeysWithExpiryCheck().size(), although see that method for the approximate time that would take.

To get a very fast result, use Ehcache.getKeysNoDuplicateCheck().size(). If the disk store is being used, there will be some duplicates.

Note:getSize() is a very expensive operation in off-heap, disk and Terracotta implementations.

Specified by:
getSize in interface Ehcache
Returns:
The size value
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException

getStatus

public Status getStatus()
Gets the status attribute of the Cache.

Specified by:
getStatus in interface Ehcache
Returns:
The status value from the Status enum class

getWriterManager

public CacheWriterManager getWriterManager()
Obtain the writer manager that's used by this cache instance.

Specified by:
getWriterManager in interface Ehcache
Returns:
the writer manager that's set up for this cache

initialise

public void initialise()
Newly created caches do not have a MemoryStore or a DiskStore.

This method creates those and makes the cache ready to accept elements

This method is not intended to be called explicitly, but rather is called implicitly by the cache's CacheManager instance during the cache initialization. Invoking this method directly will likely lead to breaking.

Specified by:
initialise in interface Ehcache

isClusterCoherent

@Deprecated
public boolean isClusterCoherent()
Deprecated. Use isClusterBulkLoadEnabled() instead

Returns true if the cache is in coherent mode cluster-wide. Returns false otherwise.

It applies to coherent clustering mechanisms only e.g. Terracotta

Specified by:
isClusterCoherent in interface Ehcache
Returns:
true if the cache is in coherent mode cluster-wide, false otherwise

isDisabled

public boolean isDisabled()
Whether this cache is disabled. "Disabled" means:
  1. bootstrap is disabled
  2. puts are discarded
  3. putQuites are discarded
In all other respects the cache continues as it is.

You can disable and enable a cache programmatically through the Ehcache.setDisabled(boolean) method.

Specified by:
isDisabled in interface Ehcache
Returns:
true if the cache is disabled.

isElementInMemory

public boolean isElementInMemory(Object key)
Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval.

Since no assertions are made about the state of the Element it is possible that the Element is expired, but this method still returns true.

Specified by:
isElementInMemory in interface Ehcache
Returns:
true if an element matching the key is found in memory

isElementInMemory

public boolean isElementInMemory(Serializable key)
Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval.

Since no assertions are made about the state of the Element it is possible that the Element is expired, but this method still returns true.

Specified by:
isElementInMemory in interface Ehcache
Returns:
true if an element matching the key is found in memory

isElementOnDisk

public boolean isElementOnDisk(Object key)
Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval.

Since no assertions are made about the state of the Element it is possible that the Element is expired, but this method still returns true.

Specified by:
isElementOnDisk in interface Ehcache
Returns:
true if an element matching the key is found in the diskStore

isElementOnDisk

public boolean isElementOnDisk(Serializable key)
Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval.

Since no assertions are made about the state of the Element it is possible that the Element is expired, but this method still returns true.

Specified by:
isElementOnDisk in interface Ehcache
Returns:
true if an element matching the key is found in the diskStore

isExpired

public boolean isExpired(Element element)
                  throws IllegalStateException,
                         NullPointerException
Checks whether this cache element has expired.

The element is expired if:

  1. the idle time is non-zero and has elapsed, unless the cache is eternal; or
  2. the time to live is non-zero and has elapsed, unless the cache is eternal; or
  3. the value of the element is null.

Specified by:
isExpired in interface Ehcache
Parameters:
element - the element to check
Returns:
true if it has expired
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
NullPointerException - if the element is null

isKeyInCache

public boolean isKeyInCache(Object key)
An inexpensive check to see if the key exists in the cache.

Since no assertions are made about the state of the Element it is possible that the Element is expired, but this method still returns true.

Specified by:
isKeyInCache in interface Ehcache
Parameters:
key - the key to check for
Returns:
true if an Element matching the key is found in the cache. No assertions are made about the state of the Element.

isNodeCoherent

@Deprecated
public boolean isNodeCoherent()
Deprecated. Use isNodeBulkLoadEnabled() instead

Returns true if the cache is in coherent mode for the current node. Returns false otherwise.

It applies to coherent clustering mechanisms only e.g. Terracotta

Specified by:
isNodeCoherent in interface Ehcache
Returns:
true if the cache is in coherent mode cluster-wide, false otherwise

isValueInCache

public boolean isValueInCache(Object value)
An extremely expensive check to see if the value exists in the cache.

Specified by:
isValueInCache in interface Ehcache
Parameters:
value - to check for
Returns:
true if an Element matching the key is found in the cache. No assertions are made about the state of the Element.

registerCacheExtension

public void registerCacheExtension(CacheExtension cacheExtension)
Register a CacheExtension with the cache. It will then be tied into the cache lifecycle.

If the CacheExtension is not initialised, initialise it.

Specified by:
registerCacheExtension in interface Ehcache

registerCacheWriter

public void registerCacheWriter(CacheWriter cacheWriter)
Register the CacheWriter for this cache. It will then be tied into the cache lifecycle.

If the CacheWriter is not initialised, initialise it.

Specified by:
registerCacheWriter in interface Ehcache
Parameters:
cacheWriter - A CacheWriter to register

registerDynamicAttributesExtractor

public void registerDynamicAttributesExtractor(DynamicAttributesExtractor extractor)
Allows user to register a dynamic attribute extractor with a searchable cache that is dynamically indexable, as indicated by its configuration. Calling this method on such a cache is optional, but doing so more than once replaces previously registered extractor with the given one; i.e., there can be at most one extractor instance configured for each such cache. If the cache was not configured for dynamic indexing, an exception will be thrown

Specified by:
registerDynamicAttributesExtractor in interface Ehcache

removeQuiet

public boolean removeQuiet(Object key)
                    throws IllegalStateException
Removes an Element from the Cache, without notifying listeners. This also removes it from any stores it may be in.

Specified by:
removeQuiet in interface Ehcache
Returns:
true if the element was removed, false if it was not found in the cache
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

removeQuiet

public boolean removeQuiet(Serializable key)
                    throws IllegalStateException
Removes an Element from the Cache, without notifying listeners. This also removes it from any stores it may be in.

Specified by:
removeQuiet in interface Ehcache
Returns:
true if the element was removed, false if it was not found in the cache
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

removeWithWriter

public boolean removeWithWriter(Object key)
                         throws IllegalStateException,
                                CacheException
Removes an Element from 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:
removeWithWriter in interface Ehcache
Returns:
true if the element was removed, false if it was not found in the cache
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException - if no CacheWriter was registered

setBootstrapCacheLoader

public void setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader)
                             throws CacheException
Sets the bootstrap cache loader.

Specified by:
setBootstrapCacheLoader in interface Ehcache
Parameters:
bootstrapCacheLoader - the loader to be used
Throws:
CacheException - if this method is called after the cache is initialized

setCacheExceptionHandler

public void setCacheExceptionHandler(CacheExceptionHandler cacheExceptionHandler)
Sets an ExceptionHandler on the Cache. If one is already set, it is overwritten.

Specified by:
setCacheExceptionHandler in interface Ehcache

setCacheManager

public void setCacheManager(CacheManager cacheManager)
Sets the CacheManager

Specified by:
setCacheManager in interface Ehcache
Parameters:
cacheManager - the CacheManager for this cache to use.

setDisabled

public void setDisabled(boolean disabled)
Disables or enables this cache. This call overrides the previous value of disabled.

Specified by:
setDisabled in interface Ehcache
Parameters:
disabled - true if you wish to disable, false to enable
See Also:
Ehcache.isDisabled()

setName

public void setName(String name)
Sets the cache name which will name.

Specified by:
setName in interface Ehcache
Parameters:
name - the name of the cache. Should not be null.

setNodeCoherent

@Deprecated
public void setNodeCoherent(boolean coherent)
                     throws UnsupportedOperationException
Deprecated. Use setNodeBulkLoadEnabled(boolean) instead

Sets the cache in coherent or incoherent mode depending on the parameter on this node. Calling setNodeCoherent(true) when the cache is already in coherent mode or calling setNodeCoherent(false) when already in incoherent mode will be a no-op.

It applies to coherent clustering mechanisms only e.g. Terracotta

When using Terracotta clustered caches with nonstop enabled, the timeout used by this method is NonstopConfiguration.getBulkOpsTimeoutMultiplyFactor() times the timeout value in the config.

Specified by:
setNodeCoherent in interface Ehcache
Parameters:
coherent - true transitions to coherent mode, false to incoherent mode
Throws:
UnsupportedOperationException - if this cache does not support coherence, like RMI replication

setTransactionManagerLookup

public void setTransactionManagerLookup(TransactionManagerLookup transactionManagerLookup)
This class is used to access the transaction manager used during XA.

Specified by:
setTransactionManagerLookup in interface Ehcache

unregisterCacheExtension

public void unregisterCacheExtension(CacheExtension cacheExtension)
Unregister a CacheExtension with the cache. It will then be detached from the cache lifecycle.

Specified by:
unregisterCacheExtension in interface Ehcache

unregisterCacheWriter

public void unregisterCacheWriter()
Unregister the CacheWriter from the cache. It will then be detached from the cache lifecycle.

If not CacheWriter was registered beforehand this operation has no effect.

Specified by:
unregisterCacheWriter in interface Ehcache

waitUntilClusterCoherent

@Deprecated
public void waitUntilClusterCoherent()
                              throws UnsupportedOperationException
Deprecated. Use waitUntilClusterBulkLoadComplete() instead

This method waits until the cache is in coherent mode in all the connected nodes. If the cache is already in coherent mode it returns immediately

It applies to coherent clustering mechanisms only e.g. Terracotta

Specified by:
waitUntilClusterCoherent in interface Ehcache
Throws:
UnsupportedOperationException - if this cache does not support coherence, like RMI replication

clone

public Object clone()
             throws CloneNotSupportedException
Clones a cache. This is only legal if the cache has not been initialized. At that point only primitives have been set and no MemoryStore or DiskStore has been created.

A new, empty, RegisteredEventListeners is created on clone.

Specified by:
clone in interface Ehcache
Overrides:
clone in class Object
Returns:
an object of type Cache
Throws:
CloneNotSupportedException

putIfAbsent

public Element putIfAbsent(Element element)
                    throws NullPointerException
Put an element in the cache if no element is currently mapped to the elements key.

Specified by:
putIfAbsent in interface Ehcache
Parameters:
element - element to be added
Returns:
the element previously cached for this key, or null if none.
Throws:
NullPointerException - if the element is null, or has a null key

putIfAbsent

public Element putIfAbsent(Element element,
                           boolean doNotNotifyCacheReplicators)
                    throws NullPointerException
Description copied from interface: Ehcache
Put an element in the cache if no element is currently mapped to the elements key.

Specified by:
putIfAbsent in interface Ehcache
Parameters:
element - element to be added
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
Returns:
the element previously cached for this key, or null if none.
Throws:
NullPointerException - if the element is null, or has a null key

removeElement

public boolean removeElement(Element element)
                      throws NullPointerException
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.

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:
removeElement in interface Ehcache
Parameters:
element - Element to be removed
Returns:
true if the value was removed
Throws:
NullPointerException - if the element is null, or has a null key
See Also:
CacheConfiguration.addElementValueComparator(net.sf.ehcache.config.ElementValueComparatorConfiguration)

replace

public boolean replace(Element old,
                       Element element)
                throws NullPointerException,
                       IllegalArgumentException
Replace the cached element only if the current Element is equal to the supplied old Element.

Specified by:
replace in interface Ehcache
Parameters:
old - Element to be test against
element - Element to be cached
Returns:
true if the Element was replaced
Throws:
NullPointerException - if the either Element is null or has a null key
IllegalArgumentException - if the two Element keys are non-null but not equal

replace

public Element replace(Element element)
                throws NullPointerException
Replace the cached element only if an Element is currently cached for this key

Specified by:
replace in interface Ehcache
Parameters:
element - Element to be cached
Returns:
the Element previously cached for this key, or null if no Element was cached
Throws:
NullPointerException - if the Element is null or has a null key

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener.

Specified by:
addPropertyChangeListener in interface Ehcache
See Also:
Ehcache.addPropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener.

Specified by:
removePropertyChangeListener in interface Ehcache
See Also:
Ehcache.removePropertyChangeListener(java.beans.PropertyChangeListener)

toString

public String toString()
Returns a String representation of Cache.

Specified by:
toString in interface Ehcache
Overrides:
toString in class Object

createQuery

public Query createQuery()
Create a new query builder for this cache

Specified by:
createQuery in interface Ehcache
Returns:
a new query builder

getSearchAttribute

public <T> Attribute<T> getSearchAttribute(String attributeName)
                                throws CacheException
Retrieve the given named search attribute

Specified by:
getSearchAttribute in interface Ehcache
Type Parameters:
T - type of the attribute
Parameters:
attributeName - the name of the attribute to retrieve
Returns:
the search attribute
Throws:
CacheException - if no such attribute is defined for the given name

getSearchAttributes

public Set<Attribute> getSearchAttributes()
                                   throws CacheException
Specified by:
getSearchAttributes in interface Ehcache
Returns:
set of all search attributes in effect at the time of calling this method
Throws:
CacheException

isSearchable

public boolean isSearchable()
Is this cache searchable?

Specified by:
isSearchable in interface Ehcache
Returns:
true if this cache is searchable

acquireReadLockOnKey

public void acquireReadLockOnKey(Object key)
Acquires the proper read lock for a given cache key

Specified by:
acquireReadLockOnKey in interface Ehcache
Parameters:
key - - The key that retrieves a value that you want to protect via locking

acquireWriteLockOnKey

public void acquireWriteLockOnKey(Object key)
Acquires the proper write lock for a given cache key

Specified by:
acquireWriteLockOnKey in interface Ehcache
Parameters:
key - - The key that retrieves a value that you want to protect via locking

releaseReadLockOnKey

public void releaseReadLockOnKey(Object key)
Release a held read lock for the passed in key

Specified by:
releaseReadLockOnKey in interface Ehcache
Parameters:
key - - The key that retrieves a value that you want to protect via locking

releaseWriteLockOnKey

public void releaseWriteLockOnKey(Object key)
Release a held write lock for the passed in key

Specified by:
releaseWriteLockOnKey in interface Ehcache
Parameters:
key - - The key that retrieves a value that you want to protect via locking

tryReadLockOnKey

public boolean tryReadLockOnKey(Object key,
                                long timeout)
                         throws InterruptedException
Try to get a read lock on a given key. If can't get it in timeout millis then return a boolean telling that it didn't get the lock

Specified by:
tryReadLockOnKey in interface Ehcache
Parameters:
key - - The key that retrieves a value that you want to protect via locking
timeout - - millis until giveup on getting the lock
Returns:
whether the lock was awarded
Throws:
InterruptedException

tryWriteLockOnKey

public boolean tryWriteLockOnKey(Object key,
                                 long timeout)
                          throws InterruptedException
Try to get a write lock on a given key. If can't get it in timeout millis then return a boolean telling that it didn't get the lock

Specified by:
tryWriteLockOnKey in interface Ehcache
Parameters:
key - - The key that retrieves a value that you want to protect via locking
timeout - - millis until giveup on getting the lock
Returns:
whether the lock was awarded
Throws:
InterruptedException

isReadLockedByCurrentThread

public boolean isReadLockedByCurrentThread(Object key)
Returns true if a read lock for the key is held by the current thread

Specified by:
isReadLockedByCurrentThread in interface Ehcache
Returns:
true if a read lock for the key is held by the current thread

isWriteLockedByCurrentThread

public boolean isWriteLockedByCurrentThread(Object key)
Returns true if a write lock for the key is held by the current thread

Specified by:
isWriteLockedByCurrentThread in interface Ehcache
Returns:
true if a write lock for the key is held by the current thread

isClusterBulkLoadEnabled

public boolean isClusterBulkLoadEnabled()
                                 throws UnsupportedOperationException,
                                        TerracottaNotRunningException
Returns true if at least one node in the cluster is in bulk-load mode. Returns false otherwise.

NOTE: if Ehcache.isNodeBulkLoadEnabled() returns true, this method will always return true. Applies to caches clustered with Terracotta only.

Specified by:
isClusterBulkLoadEnabled in interface Ehcache
Returns:
true if the cache is in bulk-load mode cluster-wide, false otherwise
Throws:
UnsupportedOperationException - if the cache is not clustered with Terracotta
TerracottaNotRunningException

isNodeBulkLoadEnabled

public boolean isNodeBulkLoadEnabled()
                              throws UnsupportedOperationException,
                                     TerracottaNotRunningException
Returns true if the current node is in bulk-load mode. Returns false otherwise.

NOTE: if this method returns true, Ehcache.isClusterBulkLoadEnabled() method will always return true. Applies to caches clustered with Terracotta only.

Specified by:
isNodeBulkLoadEnabled in interface Ehcache
Returns:
true if the cache is in coherent mode cluster-wide, false otherwise
Throws:
UnsupportedOperationException - if the cache is not clustered with Terracotta
TerracottaNotRunningException

setNodeBulkLoadEnabled

public void setNodeBulkLoadEnabled(boolean enabledBulkLoad)
                            throws UnsupportedOperationException,
                                   TerracottaNotRunningException
Enable/disable bulk-load mode in this node for this cache. Calling setBulkLoadEnabled(true) when the cache is already in bulk-load mode or calling setBulkLoadEnabled(false) when already NOT in bulk-load mode will be a no-op.

Applies to caches clustered with Terracotta only.

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:
setNodeBulkLoadEnabled in interface Ehcache
Parameters:
enabledBulkLoad - true enables bulk-load, false disables it if not already disabled
Throws:
UnsupportedOperationException - if the cache is not clustered with Terracotta
TerracottaNotRunningException

waitUntilClusterBulkLoadComplete

public void waitUntilClusterBulkLoadComplete()
                                      throws UnsupportedOperationException,
                                             TerracottaNotRunningException
This method waits until all the connected nodes have disabled bulk-load. Or in other words, calling this method will block until all connected nodes in the cluster disables bulk-load. If none of the nodes did not enable bulk-load this method will return immediately

Applies to caches clustered with Terracotta only.

Specified by:
waitUntilClusterBulkLoadComplete in interface Ehcache
Throws:
UnsupportedOperationException - if the cache is not clustered with Terracotta
TerracottaNotRunningException

removeAndReturnElement

public Element removeAndReturnElement(Object key)
                               throws IllegalStateException
Removes and returns the element associated with the key

Specified by:
removeAndReturnElement in interface InternalEhcache
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:
IllegalStateException

recalculateSize

public void recalculateSize(Object key)
Recalculate the size of the element mapped to the key

Specified by:
recalculateSize in interface InternalEhcache
Parameters:
key - the key

getStatistics

public StatisticsGateway getStatistics()
                                throws IllegalStateException
Description copied from interface: Ehcache
Gets an immutable Statistics object representing the Cache statistics at the time. How the statistics are calculated depends on the statistics accuracy setting. The only aspect of statistics sensitive to the accuracy setting is object size. How that is calculated is discussed below.

Best Effort Size

This result is returned when the statistics accuracy setting is Statistics#STATISTICS_ACCURACY_BEST_EFFORT.

The size is the number of Elements in the MemoryStore plus the number of Elements in the DiskStore.

This number is the actual number of elements, including expired elements that have not been removed. Any duplicates between stores are accounted for.

Expired elements are removed from the the memory store when getting an expired element, or when attempting to spool an expired element to disk.

Expired elements are removed from the disk store when getting an expired element, or when the expiry thread runs, which is once every five minutes.

Guaranteed Accuracy Size

This result is returned when the statistics accuracy setting is Statistics#STATISTICS_ACCURACY_GUARANTEED.

This method accounts for elements which might be expired or duplicated between stores. It take approximately 200ms per 1000 elements to execute.

Fast but non-accurate Size

This result is returned when the statistics accuracy setting is Statistics#STATISTICS_ACCURACY_NONE.

The number given may contain expired elements. In addition if the DiskStore is used it may contain some double counting of elements. It takes 6ms for 1000 elements to execute. Time to execute is O(log n). 50,000 elements take 36ms.

Specified by:
getStatistics in interface Ehcache
Returns:
the number of elements in the ehcache, with a varying degree of accuracy, depending on accuracy setting.
Throws:
IllegalStateException - if the cache is not Status.STATUS_ALIVE

ehcache

Copyright 2001-2014, Terracotta, Inc.