Class ClassLoaderAwareCache
- java.lang.Object
-
- net.sf.ehcache.constructs.classloader.ClassLoaderAwareCache
-
- All Implemented Interfaces:
java.lang.Cloneable,Ehcache
- Direct Known Subclasses:
InternalClassLoaderAwareCache
public class ClassLoaderAwareCache extends java.lang.Object implements Ehcache
A cache decorator that adjusts the Thread context classloader (TCCL) for every cache operation. The TCCL is reset to its original value when the method is complete- Author:
- teck
-
-
Field Summary
Fields Modifier and Type Field Description protected EhcachecacheUsed by InternalClassLoaderAwareCacheprotected java.lang.ClassLoaderclassLoaderUsed by InternalClassLoaderAwareCache
-
Constructor Summary
Constructors Constructor Description ClassLoaderAwareCache(Ehcache cache, java.lang.ClassLoader classLoader)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidacquireReadLockOnKey(java.lang.Object arg0)Acquires the proper read lock for a given cache keyvoidacquireWriteLockOnKey(java.lang.Object arg0)Acquires the proper write lock for a given cache keyvoidaddPropertyChangeListener(java.beans.PropertyChangeListener arg0)Add a PropertyChangeListener.voidbootstrap()Bootstrap command.longcalculateInMemorySize()Deprecated.longcalculateOffHeapSize()Deprecated.longcalculateOnDiskSize()Deprecated.java.lang.Objectclone()Clones a cache.QuerycreateQuery()Create a new query builder for this cachevoiddisableDynamicFeatures()Disables dynamic configuration and disable/enable for this cache.voiddispose()Flushes all cache items from memory to auxilliary caches and close the auxilliary caches.voidevictExpiredElements()Causes all elements stored in the Cache to be synchronously checked for expiry, and if expired, evicted.voidflush()Flushes all cache items from memory to the disk store, and from the DiskStore to disk.Elementget(java.io.Serializable arg0)Gets an element from the cache.Elementget(java.lang.Object arg0)Gets an element from the cache.java.util.MapgetAll(java.util.Collection arg0)Gets all the elements from the cache for the keys provided.java.util.MapgetAllWithLoader(java.util.Collection arg0, java.lang.Object arg1)The getAll method will return, from the cache, a Map of the objects associated with the Collection of keys in argument "keys".BootstrapCacheLoadergetBootstrapCacheLoader()Accessor for the BootstrapCacheLoader associated with this cache.CacheConfigurationgetCacheConfiguration()Gets the cache configuration this cache was created with.RegisteredEventListenersgetCacheEventNotificationService()Use this to access the service in order to register and unregister listenersCacheExceptionHandlergetCacheExceptionHandler()CacheManagergetCacheManager()Gets the CacheManager managing this cache.intgetDiskStoreSize()Deprecated.java.lang.StringgetGuid()The GUID for this cache instance can be used to determine whether two cache instance references are pointing to the same cache.java.lang.ObjectgetInternalContext()This should not be usedjava.util.ListgetKeys()Returns a list of all elements in the cache, whether or not they are expired.java.util.ListgetKeysNoDuplicateCheck()Returns a list of all elements in the cache, whether or not they are expired.java.util.ListgetKeysWithExpiryCheck()Returns a list of all elements in the cache.longgetMemoryStoreSize()Deprecated.java.lang.StringgetName()Gets the cache name.longgetOffHeapStoreSize()Deprecated.ElementgetQuiet(java.io.Serializable arg0)Gets an element from the cache, without updating Element statistics.ElementgetQuiet(java.lang.Object arg0)Gets an element from the cache, without updating Element statistics.java.util.ListgetRegisteredCacheExtensions()java.util.ListgetRegisteredCacheLoaders()CacheWritergetRegisteredCacheWriter()Retrieves theCacheWriterthat was registered for this cache.AttributegetSearchAttribute(java.lang.String arg0)Retrieve the given named search attributejava.util.Set<Attribute>getSearchAttributes()intgetSize()Gets the size of the cache.StatisticsGatewaygetStatistics()Gets an immutable Statistics object representing the Cache statistics at the time.StatusgetStatus()Gets the status attribute of the Cache.ElementgetWithLoader(java.lang.Object arg0, CacheLoader arg1, java.lang.Object arg2)This method will return, from the cache, the object associated with the argument "key".CacheWriterManagergetWriterManager()Obtain the writer manager that's used by this cache instance.booleanhasAbortedSizeOf()Check if the cache may contain elements which the SizeOf engine could not fully size.voidinitialise()Newly created caches do not have aMemoryStoreor aDiskStore.booleanisClusterBulkLoadEnabled()Returns true if at least one node in the cluster is in bulk-load mode.booleanisClusterCoherent()Returns true if the cache is in coherent mode cluster-wide.booleanisDisabled()Whether this cache is disabled.booleanisElementInMemory(java.io.Serializable arg0)Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval.booleanisElementInMemory(java.lang.Object arg0)Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval.booleanisElementOnDisk(java.io.Serializable arg0)Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval.booleanisElementOnDisk(java.lang.Object arg0)Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval.booleanisExpired(Element arg0)Checks whether this cache element has expired.booleanisKeyInCache(java.lang.Object arg0)An inexpensive check to see if the key exists in the cache.booleanisNodeBulkLoadEnabled()Returns true if the current node is in bulk-load mode.booleanisNodeCoherent()Returns true if the cache is in coherent mode for the current node.booleanisReadLockedByCurrentThread(java.lang.Object arg0)Returns true if a read lock for the key is held by the current threadbooleanisSearchable()Is this cache searchable?booleanisValueInCache(java.lang.Object arg0)An extremely expensive check to see if the value exists in the cache.booleanisWriteLockedByCurrentThread(java.lang.Object arg0)Returns true if a write lock for the key is held by the current threadvoidload(java.lang.Object arg0)The load method provides a means to "pre load" the cache.voidloadAll(java.util.Collection arg0, java.lang.Object arg1)The loadAll method provides a means to "pre load" objects into the cache.static voidmain(java.lang.String[] args)Generator for the method bodiesvoidput(Element arg0)Put an element in the cache.voidput(Element arg0, boolean arg1)Put an element in the cache.voidputAll(java.util.Collection arg0)Puts a collection of elements in to the cache.ElementputIfAbsent(Element arg0)Put an element in the cache if no element is currently mapped to the elements key.ElementputIfAbsent(Element arg0, boolean arg1)Put an element in the cache if no element is currently mapped to the elements key.voidputQuiet(Element arg0)Put an element in the cache, without updating statistics, or updating listeners.voidputWithWriter(Element arg0)Put an element in the cache writing through a CacheWriter.voidregisterCacheExtension(CacheExtension arg0)Register aCacheExtensionwith the cache.voidregisterCacheLoader(CacheLoader arg0)Register aCacheLoaderwith the cache.voidregisterCacheWriter(CacheWriter arg0)Register theCacheWriterfor this cache.voidregisterDynamicAttributesExtractor(DynamicAttributesExtractor extractor)Allows user to register a dynamic attribute extractor with a searchable cache that is dynamically indexable, as indicated by its configuration.voidreleaseReadLockOnKey(java.lang.Object arg0)Release a held read lock for the passed in keyvoidreleaseWriteLockOnKey(java.lang.Object arg0)Release a held write lock for the passed in keybooleanremove(java.io.Serializable arg0)Removes anElementfrom the Cache.booleanremove(java.io.Serializable arg0, boolean arg1)Removes anElementfrom the Cache.booleanremove(java.lang.Object arg0)Removes anElementfrom the Cache.booleanremove(java.lang.Object arg0, boolean arg1)Removes anElementfrom the Cache.voidremoveAll()Removes all cached items.voidremoveAll(boolean arg0)Removes all cached items.voidremoveAll(java.util.Collection arg0)Removes given set ofElementfrom the Cache.voidremoveAll(java.util.Collection arg0, boolean arg1)Removes all cached items.booleanremoveElement(Element arg0)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.voidremovePropertyChangeListener(java.beans.PropertyChangeListener arg0)Remove a PropertyChangeListener.booleanremoveQuiet(java.io.Serializable arg0)Removes anElementfrom the Cache, without notifying listeners.booleanremoveQuiet(java.lang.Object arg0)Removes anElementfrom the Cache, without notifying listeners.booleanremoveWithWriter(java.lang.Object arg0)Removes anElementfrom the Cache and any stores it might be in.Elementreplace(Element arg0)Replace the cached element only if an Element is currently cached for this keybooleanreplace(Element arg0, Element arg1)Replace the cached element only if the current Element is equal to the supplied old Element.voidsetBootstrapCacheLoader(BootstrapCacheLoader arg0)Sets the bootstrap cache loader.voidsetCacheExceptionHandler(CacheExceptionHandler arg0)Sets an ExceptionHandler on the Cache.voidsetCacheManager(CacheManager arg0)Sets the CacheManagervoidsetDisabled(boolean arg0)Disables or enables this cache.voidsetName(java.lang.String arg0)Sets the cache name which will name.voidsetNodeBulkLoadEnabled(boolean arg0)Enable/disable bulk-load mode in this node for this cache.voidsetNodeCoherent(boolean arg0)Sets the cache in coherent or incoherent mode depending on the parameter on this node.voidsetTransactionManagerLookup(TransactionManagerLookup arg0)This class is used to access the transaction manager used during XA.java.lang.StringtoString()Returns aStringrepresentation ofCache.booleantryReadLockOnKey(java.lang.Object arg0, long arg1)Try to get a read lock on a given key.booleantryWriteLockOnKey(java.lang.Object arg0, long arg1)Try to get a write lock on a given key.voidunregisterCacheExtension(CacheExtension arg0)Unregister aCacheExtensionwith the cache.voidunregisterCacheLoader(CacheLoader arg0)Unregister aCacheLoaderwith the cache.voidunregisterCacheWriter()Unregister theCacheWriterfrom the cache.voidwaitUntilClusterBulkLoadComplete()This method waits until all the connected nodes have disabled bulk-load.voidwaitUntilClusterCoherent()This method waits until the cache is in coherent mode in all the connected nodes.
-
-
-
Field Detail
-
classLoader
protected final java.lang.ClassLoader classLoader
Used by InternalClassLoaderAwareCache
-
cache
protected final Ehcache cache
Used by InternalClassLoaderAwareCache
-
-
Constructor Detail
-
ClassLoaderAwareCache
public ClassLoaderAwareCache(Ehcache cache, java.lang.ClassLoader classLoader)
Constructor- Parameters:
cache- wrapped cacheclassLoader- loader to set Thread context loader to for duration of cache opeartion
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
Generator for the method bodies- Parameters:
args-
-
putQuiet
public void putQuiet(Element arg0) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, CacheException
Put 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- Parameters:
arg0- 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 arg0) throws java.lang.IllegalArgumentException, java.lang.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:
- 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- Parameters:
arg0- 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
-
getAll
public java.util.Map getAll(java.util.Collection arg0) throws java.lang.IllegalStateException, CacheException, java.lang.NullPointerExceptionGets 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- Parameters:
arg0- 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_ALIVEjava.lang.NullPointerException- if any key is null in the collectionCacheException- See Also:
Ehcache.isExpired(net.sf.ehcache.Element)
-
getQuiet
public Element getQuiet(java.io.Serializable arg0) throws java.lang.IllegalStateException, CacheException
Gets an element from the cache, without updating Element statistics. Cache statistics are still updated.- Specified by:
getQuietin interfaceEhcache- Parameters:
arg0- 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 arg0) throws java.lang.IllegalStateException, CacheException
Gets an element from the cache, without updating Element statistics. Cache statistics are also not updated.- Specified by:
getQuietin interfaceEhcache- Parameters:
arg0- 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)
-
getKeysWithExpiryCheck
public java.util.List getKeysWithExpiryCheck() throws java.lang.IllegalStateException, CacheExceptionReturns 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:
getKeysWithExpiryCheckin interfaceEhcache- Returns:
- a list of
Objectkeys - Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException
-
getKeysNoDuplicateCheck
public java.util.List getKeysNoDuplicateCheck() throws java.lang.IllegalStateExceptionReturns 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:
getKeysNoDuplicateCheckin interfaceEhcache- Returns:
- a list of
Objectkeys - Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
removeQuiet
public boolean removeQuiet(java.io.Serializable arg0) throws java.lang.IllegalStateExceptionRemoves anElementfrom the Cache, without notifying listeners. This also removes it from any stores it may be in.- Specified by:
removeQuietin interfaceEhcache- Parameters:
arg0- 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 arg0) throws java.lang.IllegalStateExceptionRemoves anElementfrom the Cache, without notifying listeners. This also removes it from any stores it may be in.- Specified by:
removeQuietin interfaceEhcache- Parameters:
arg0- 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 arg0) throws java.lang.IllegalStateException, CacheExceptionRemoves 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- Parameters:
arg0- 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
-
calculateInMemorySize
@Deprecated public long calculateInMemorySize() throws java.lang.IllegalStateException, CacheExceptionDeprecated.Gets the size of the memory store for this cacheWarning: 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:
calculateInMemorySizein interfaceEhcache- Returns:
- the approximate size of the memory store in bytes
- Throws:
java.lang.IllegalStateExceptionCacheException
-
calculateOffHeapSize
@Deprecated public long calculateOffHeapSize() throws java.lang.IllegalStateException, CacheExceptionDeprecated.Gets the size of the off-heap store for this cache- Specified by:
calculateOffHeapSizein interfaceEhcache- Returns:
- the size of the off-heap store in bytes
- Throws:
java.lang.IllegalStateExceptionCacheException
-
calculateOnDiskSize
@Deprecated public long calculateOnDiskSize() throws java.lang.IllegalStateException, CacheExceptionDeprecated.Gets the size of the on-disk store for this cache- Specified by:
calculateOnDiskSizein interfaceEhcache- Returns:
- the size of the on-disk store in bytes
- Throws:
java.lang.IllegalStateExceptionCacheException
-
hasAbortedSizeOf
public boolean hasAbortedSizeOf()
Check if the cache may contain elements which the SizeOf engine could not fully size.- Specified by:
hasAbortedSizeOfin interfaceEhcache- Returns:
- true if the cache may contain partially sized objects
-
getMemoryStoreSize
@Deprecated public long getMemoryStoreSize() throws java.lang.IllegalStateExceptionDeprecated.Returns the number of elements in the memory store.- Specified by:
getMemoryStoreSizein interfaceEhcache- Returns:
- the number of elements in the memory store
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
getOffHeapStoreSize
@Deprecated public long getOffHeapStoreSize() throws java.lang.IllegalStateExceptionDeprecated.Returns the number of elements in the off-heap store.- Specified by:
getOffHeapStoreSizein interfaceEhcache- Returns:
- the number of elements in the off-heap store
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
getDiskStoreSize
@Deprecated public int getDiskStoreSize() throws java.lang.IllegalStateExceptionDeprecated.Returns the number of elements in the disk store.- Specified by:
getDiskStoreSizein interfaceEhcache- Returns:
- the number of elements in the disk store.
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
isExpired
public boolean isExpired(Element arg0) throws java.lang.IllegalStateException, java.lang.NullPointerException
Checks whether this cache element has expired.The element is expired if:
- the idle time is non-zero and has elapsed, unless the cache is eternal; or
- the time to live is non-zero and has elapsed, unless the cache is eternal; or
- the value of the element is null.
- Specified by:
isExpiredin interfaceEhcache- Parameters:
arg0- the element to check- Returns:
- true if it has expired
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVEjava.lang.NullPointerException- if the element is null
-
getCacheEventNotificationService
public RegisteredEventListeners getCacheEventNotificationService()
Use this to access the service in order to register and unregister listeners- Specified by:
getCacheEventNotificationServicein interfaceEhcache- Returns:
- the RegisteredEventListeners instance for this cache.
-
isElementInMemory
public boolean isElementInMemory(java.lang.Object arg0)
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:
isElementInMemoryin interfaceEhcache- Parameters:
arg0- the key of the element to remove- Returns:
- true if an element matching the key is found in memory
-
isElementInMemory
public boolean isElementInMemory(java.io.Serializable arg0)
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:
isElementInMemoryin interfaceEhcache- Parameters:
arg0- the key of the element to remove- Returns:
- true if an element matching the key is found in memory
-
isElementOnDisk
public boolean isElementOnDisk(java.lang.Object arg0)
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:
isElementOnDiskin interfaceEhcache- Parameters:
arg0- the key of the element to remove- Returns:
- true if an element matching the key is found in the diskStore
-
isElementOnDisk
public boolean isElementOnDisk(java.io.Serializable arg0)
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:
isElementOnDiskin interfaceEhcache- Parameters:
arg0- the key of the element to remove- Returns:
- true if an element matching the key is found in the diskStore
-
getGuid
public java.lang.String getGuid()
The GUID for this cache instance can be used to determine whether two cache instance references are pointing to the same cache.
-
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:
getCacheManagerin interfaceEhcache- Returns:
- the manager or null if there is none
-
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:
evictExpiredElementsin interfaceEhcache
-
isKeyInCache
public boolean isKeyInCache(java.lang.Object arg0)
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:
isKeyInCachein interfaceEhcache- Parameters:
arg0- 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.
-
isValueInCache
public boolean isValueInCache(java.lang.Object arg0)
An extremely expensive check to see if the value exists in the cache.- Specified by:
isValueInCachein interfaceEhcache- Parameters:
arg0- 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.
-
getStatistics
public StatisticsGateway getStatistics() throws java.lang.IllegalStateException
Gets an immutable Statistics object representing the Cache statistics at the time.- Specified by:
getStatisticsin interfaceEhcache- Returns:
- the statistics gateway
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
setCacheManager
public void setCacheManager(CacheManager arg0)
Sets the CacheManager- Specified by:
setCacheManagerin interfaceEhcache- Parameters:
arg0- the CacheManager for this cache to use.
-
getBootstrapCacheLoader
public BootstrapCacheLoader getBootstrapCacheLoader()
Accessor for the BootstrapCacheLoader associated with this cache. For testing purposes.- Specified by:
getBootstrapCacheLoaderin interfaceEhcache- Returns:
- the BootstrapCacheLoader to use
-
setBootstrapCacheLoader
public void setBootstrapCacheLoader(BootstrapCacheLoader arg0) throws CacheException
Sets the bootstrap cache loader.- Specified by:
setBootstrapCacheLoaderin interfaceEhcache- Parameters:
arg0- the loader to be used- Throws:
CacheException- if this method is called after the cache is initialized
-
initialise
public void initialise()
Newly created caches do not have aMemoryStoreor aDiskStore.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
CacheManagerinstance during the cache initialization. Invoking this method directly will likely lead to breaking.- Specified by:
initialisein interfaceEhcache
-
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
CacheManagerinstance during the cache initialization. Invoking this method directly will likely lead to breaking.
-
getCacheConfiguration
public CacheConfiguration getCacheConfiguration()
Gets the cache configuration this cache was created with.Things like listeners that are added dynamically are excluded.
- Specified by:
getCacheConfigurationin interfaceEhcache- Returns:
- CacheConfiguration the cache configuration
-
registerCacheExtension
public void registerCacheExtension(CacheExtension arg0)
Register aCacheExtensionwith the cache. It will then be tied into the cache lifecycle.If the CacheExtension is not initialised, initialise it.
- Specified by:
registerCacheExtensionin interfaceEhcache- Parameters:
arg0- the cache extension
-
unregisterCacheExtension
public void unregisterCacheExtension(CacheExtension arg0)
Unregister aCacheExtensionwith the cache. It will then be detached from the cache lifecycle.- Specified by:
unregisterCacheExtensionin interfaceEhcache- Parameters:
arg0- the cache extension
-
getRegisteredCacheExtensions
public java.util.List getRegisteredCacheExtensions()
- Specified by:
getRegisteredCacheExtensionsin interfaceEhcache- Returns:
- the cache extensions as a live list
-
setCacheExceptionHandler
public void setCacheExceptionHandler(CacheExceptionHandler arg0)
Sets an ExceptionHandler on the Cache. If one is already set, it is overwritten.- Specified by:
setCacheExceptionHandlerin interfaceEhcache- Parameters:
arg0- the cache exception handler
-
getCacheExceptionHandler
public CacheExceptionHandler getCacheExceptionHandler()
- Specified by:
getCacheExceptionHandlerin interfaceEhcache- Returns:
- an ExceptionHandler on the Cache
-
registerCacheLoader
public void registerCacheLoader(CacheLoader arg0)
Register aCacheLoaderwith 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:
registerCacheLoaderin interfaceEhcache- Parameters:
arg0- A Cache Loader to register
-
unregisterCacheLoader
public void unregisterCacheLoader(CacheLoader arg0)
Unregister aCacheLoaderwith the cache. It will then be detached from the cache lifecycle.- Specified by:
unregisterCacheLoaderin interfaceEhcache- Parameters:
arg0- A Cache Loader to unregister
-
getRegisteredCacheLoaders
public java.util.List getRegisteredCacheLoaders()
- Specified by:
getRegisteredCacheLoadersin interfaceEhcache- Returns:
- the cache loaders as a live list
-
registerCacheWriter
public void registerCacheWriter(CacheWriter arg0)
Register theCacheWriterfor this cache. It will then be tied into the cache lifecycle.If the
CacheWriteris not initialised, initialise it.- Specified by:
registerCacheWriterin interfaceEhcache- Parameters:
arg0- 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:
registerDynamicAttributesExtractorin interfaceEhcache- Parameters:
extractor- the dynamic attribute extractor
-
unregisterCacheWriter
public void unregisterCacheWriter()
Unregister theCacheWriterfrom the cache. It will then be detached from the cache lifecycle.If not
CacheWriterwas registered beforehand this operation has no effect.- Specified by:
unregisterCacheWriterin interfaceEhcache
-
getRegisteredCacheWriter
public CacheWriter getRegisteredCacheWriter()
Retrieves theCacheWriterthat was registered for this cache.- Specified by:
getRegisteredCacheWriterin interfaceEhcache- Returns:
- the registered
CacheWriter; ornullif none was registered before
-
getWithLoader
public Element getWithLoader(java.lang.Object arg0, CacheLoader arg1, java.lang.Object arg2) 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:
getWithLoaderin interfaceEhcache- Parameters:
arg0- key whose associated value is to be returned.arg1- the override loader to use. If null, the cache's default loader will be usedarg2- 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 arg0, java.lang.Object arg1) throws CacheExceptionThe 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- Parameters:
arg0- a collection of keys to be returned/loadedarg1- 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
-
isDisabled
public boolean isDisabled()
Whether this cache is disabled. "Disabled" means:- bootstrap is disabled
- puts are discarded
- putQuites are discarded
You can disable and enable a cache programmatically through the
Ehcache.setDisabled(boolean)method.- Specified by:
isDisabledin interfaceEhcache- Returns:
- true if the cache is disabled.
-
setDisabled
public void setDisabled(boolean arg0)
Disables or enables this cache. This call overrides the previous value of disabled.- Specified by:
setDisabledin interfaceEhcache- Parameters:
arg0- true if you wish to disable, false to enable- See Also:
Ehcache.isDisabled()
-
getInternalContext
public java.lang.Object getInternalContext()
This should not be used- Specified by:
getInternalContextin interfaceEhcache- Returns:
- some internal context (generally will be null)
-
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:
disableDynamicFeaturesin interfaceEhcache
-
getWriterManager
public CacheWriterManager getWriterManager()
Obtain the writer manager that's used by this cache instance.- Specified by:
getWriterManagerin interfaceEhcache- Returns:
- the writer manager that's set up for this cache
-
isClusterCoherent
public boolean isClusterCoherent() throws TerracottaNotRunningExceptionReturns 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:
isClusterCoherentin interfaceEhcache- Returns:
- true if the cache is in coherent mode cluster-wide, false otherwise
- Throws:
TerracottaNotRunningException
-
isNodeCoherent
public boolean isNodeCoherent() throws TerracottaNotRunningExceptionReturns 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:
isNodeCoherentin interfaceEhcache- Returns:
- true if the cache is in coherent mode cluster-wide, false otherwise
- Throws:
TerracottaNotRunningException
-
setNodeCoherent
public void setNodeCoherent(boolean arg0) throws java.lang.UnsupportedOperationException, TerracottaNotRunningExceptionSets the cache in coherent or incoherent mode depending on the parameter on this node. CallingsetNodeCoherent(true)when the cache is already in coherent mode or callingsetNodeCoherent(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:
setNodeCoherentin interfaceEhcache- Parameters:
arg0- true transitions to coherent mode, false to incoherent mode- Throws:
java.lang.UnsupportedOperationException- if this cache does not support coherence, like RMI replicationTerracottaNotRunningException
-
waitUntilClusterCoherent
public void waitUntilClusterCoherent() throws java.lang.UnsupportedOperationException, TerracottaNotRunningExceptionThis method waits until the cache is in coherent mode in all the connected nodes. If the cache is already in coherent mode it returns immediatelyIt applies to coherent clustering mechanisms only e.g. Terracotta
- Specified by:
waitUntilClusterCoherentin interfaceEhcache- Throws:
java.lang.UnsupportedOperationException- if this cache does not support coherence, like RMI replicationTerracottaNotRunningException
-
setTransactionManagerLookup
public void setTransactionManagerLookup(TransactionManagerLookup arg0)
This class is used to access the transaction manager used during XA.- Specified by:
setTransactionManagerLookupin interfaceEhcache- Parameters:
arg0- the transactionManagerLookup
-
getSearchAttribute
public Attribute getSearchAttribute(java.lang.String arg0) throws CacheException
Retrieve the given named search attribute- Specified by:
getSearchAttributein interfaceEhcache- Parameters:
arg0- 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 java.util.Set<Attribute> getSearchAttributes() throws CacheException
- Specified by:
getSearchAttributesin interfaceEhcache- Returns:
- set of all search attributes in effect at the time of calling this method
- Throws:
CacheException- a runtime cache exception
-
createQuery
public Query createQuery()
Create a new query builder for this cache- Specified by:
createQueryin interfaceEhcache- Returns:
- a new query builder
-
isSearchable
public boolean isSearchable()
Is this cache searchable?- Specified by:
isSearchablein interfaceEhcache- Returns:
- true if this cache is searchable
-
acquireReadLockOnKey
public void acquireReadLockOnKey(java.lang.Object arg0)
Acquires the proper read lock for a given cache key- Specified by:
acquireReadLockOnKeyin interfaceEhcache- Parameters:
arg0- - The key that retrieves a value that you want to protect via locking
-
acquireWriteLockOnKey
public void acquireWriteLockOnKey(java.lang.Object arg0)
Acquires the proper write lock for a given cache key- Specified by:
acquireWriteLockOnKeyin interfaceEhcache- Parameters:
arg0- - The key that retrieves a value that you want to protect via locking
-
tryReadLockOnKey
public boolean tryReadLockOnKey(java.lang.Object arg0, long arg1) throws java.lang.InterruptedExceptionTry 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:
tryReadLockOnKeyin interfaceEhcache- Parameters:
arg0- - The key that retrieves a value that you want to protect via lockingarg1- - millis until giveup on getting the lock- Returns:
- whether the lock was awarded
- Throws:
java.lang.InterruptedException- if the thread was interrupted
-
tryWriteLockOnKey
public boolean tryWriteLockOnKey(java.lang.Object arg0, long arg1) throws java.lang.InterruptedExceptionTry 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:
tryWriteLockOnKeyin interfaceEhcache- Parameters:
arg0- - The key that retrieves a value that you want to protect via lockingarg1- - millis until giveup on getting the lock- Returns:
- whether the lock was awarded
- Throws:
java.lang.InterruptedException- if the thread was interrupted
-
releaseReadLockOnKey
public void releaseReadLockOnKey(java.lang.Object arg0)
Release a held read lock for the passed in key- Specified by:
releaseReadLockOnKeyin interfaceEhcache- Parameters:
arg0- - The key that retrieves a value that you want to protect via locking
-
releaseWriteLockOnKey
public void releaseWriteLockOnKey(java.lang.Object arg0)
Release a held write lock for the passed in key- Specified by:
releaseWriteLockOnKeyin interfaceEhcache- Parameters:
arg0- - The key that retrieves a value that you want to protect via locking
-
isReadLockedByCurrentThread
public boolean isReadLockedByCurrentThread(java.lang.Object arg0) throws java.lang.UnsupportedOperationExceptionReturns true if a read lock for the key is held by the current thread- Specified by:
isReadLockedByCurrentThreadin interfaceEhcache- Parameters:
arg0- the key- Returns:
- true if a read lock for the key is held by the current thread
- Throws:
java.lang.UnsupportedOperationException- if querying the read lock state is not supported
-
isWriteLockedByCurrentThread
public boolean isWriteLockedByCurrentThread(java.lang.Object arg0) throws java.lang.UnsupportedOperationExceptionReturns true if a write lock for the key is held by the current thread- Specified by:
isWriteLockedByCurrentThreadin interfaceEhcache- Parameters:
arg0- the key- Returns:
- true if a write lock for the key is held by the current thread
- Throws:
java.lang.UnsupportedOperationException- if querying the write lock state is not supported
-
isClusterBulkLoadEnabled
public boolean isClusterBulkLoadEnabled() throws java.lang.UnsupportedOperationException, TerracottaNotRunningExceptionReturns 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:
isClusterBulkLoadEnabledin interfaceEhcache- Returns:
- true if the cache is in bulk-load mode cluster-wide, false otherwise
- Throws:
java.lang.UnsupportedOperationException- if the cache is not clustered with TerracottaTerracottaNotRunningException
-
isNodeBulkLoadEnabled
public boolean isNodeBulkLoadEnabled() throws java.lang.UnsupportedOperationException, TerracottaNotRunningExceptionReturns 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:
isNodeBulkLoadEnabledin interfaceEhcache- Returns:
- true if the cache is in coherent mode cluster-wide, false otherwise
- Throws:
java.lang.UnsupportedOperationException- if the cache is not clustered with TerracottaTerracottaNotRunningException
-
setNodeBulkLoadEnabled
public void setNodeBulkLoadEnabled(boolean arg0) throws java.lang.UnsupportedOperationException, TerracottaNotRunningExceptionEnable/disable bulk-load mode in this node for this cache. CallingsetBulkLoadEnabled(true)when the cache is already in bulk-load mode or callingsetBulkLoadEnabled(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:
setNodeBulkLoadEnabledin interfaceEhcache- Parameters:
arg0- true enables bulk-load, false disables it if not already disabled- Throws:
java.lang.UnsupportedOperationException- if the cache is not clustered with TerracottaTerracottaNotRunningException
-
waitUntilClusterBulkLoadComplete
public void waitUntilClusterBulkLoadComplete() throws java.lang.UnsupportedOperationException, TerracottaNotRunningExceptionThis 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 immediatelyApplies to caches clustered with Terracotta only.
- Specified by:
waitUntilClusterBulkLoadCompletein interfaceEhcache- Throws:
java.lang.UnsupportedOperationException- if the cache is not clustered with TerracottaTerracottaNotRunningException
-
loadAll
public void loadAll(java.util.Collection arg0, java.lang.Object arg1) throws CacheExceptionThe 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.- Specified by:
loadAllin interfaceEhcache- Parameters:
arg0- - 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.arg1- can be anything that makes sense to the loaderThe Ehcache native API provides similar functionality to loaders using the decorator
SelfPopulatingCache- Throws:
CacheException
-
toString
public java.lang.String toString()
Returns aStringrepresentation ofCache.
-
get
public Element get(java.lang.Object arg0) throws java.lang.IllegalStateException, CacheException
Gets 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- Parameters:
arg0- 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)
-
get
public Element get(java.io.Serializable arg0) throws java.lang.IllegalStateException, CacheException
Gets 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- Parameters:
arg0- 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)
-
put
public void put(Element arg0) throws java.lang.IllegalArgumentException, java.lang.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:
- 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- Parameters:
arg0- 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
-
put
public void put(Element arg0, boolean arg1) throws java.lang.IllegalArgumentException, java.lang.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:
- 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- Parameters:
arg0- An object. If Serializable it can fully participate in replication and the DiskStore.arg1- 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
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionClones a cache. This is only legal if the cache has not been initialized. At that point only primitives have been set and noMemoryStoreorDiskStorehas been created.A new, empty, RegisteredEventListeners is created on clone.
-
getName
public java.lang.String getName()
Gets the cache name.
-
replace
public Element replace(Element arg0) throws java.lang.NullPointerException
Replace the cached element only if an Element is currently cached for this key
-
replace
public boolean replace(Element arg0, Element arg1) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
Replace the cached element only if the current Element is equal to the supplied old Element.- Specified by:
replacein interfaceEhcache- Parameters:
arg0- Element to be test againstarg1- 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
-
putAll
public void putAll(java.util.Collection arg0) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException, CacheExceptionPuts 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- Parameters:
arg0- 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
-
remove
public boolean remove(java.io.Serializable arg0, boolean arg1) throws java.lang.IllegalStateExceptionRemoves 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- Parameters:
arg0- the key of the element to removearg1- 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.lang.Object arg0) throws java.lang.IllegalStateExceptionRemoves 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- Parameters:
arg0- 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
-
remove
public boolean remove(java.io.Serializable arg0) throws java.lang.IllegalStateExceptionRemoves 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- Parameters:
arg0- 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
-
remove
public boolean remove(java.lang.Object arg0, boolean arg1) throws java.lang.IllegalStateExceptionRemoves 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- Parameters:
arg0- of the element to removearg1- 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
-
load
public void load(java.lang.Object arg0) throws CacheExceptionThe 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:
loadin interfaceEhcache- Parameters:
arg0- key whose associated value to be loaded using the associated cacheloader if this cache doesn't contain it.- Throws:
CacheException- a runtime cache exception
-
setName
public void setName(java.lang.String arg0)
Sets the cache name which will name.
-
flush
public void flush() throws java.lang.IllegalStateException, CacheExceptionFlushes all cache items from memory to the disk store, and from the DiskStore to disk.- Specified by:
flushin interfaceEhcache- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException
-
getSize
public int getSize() throws java.lang.IllegalStateException, CacheExceptionGets the size of the cache. This is a subtle concept. See below.The size is the number of
Elements in theMemoryStoreplus the number ofElements in theDiskStore.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:
getSizein interfaceEhcache- Returns:
- The size value
- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException
-
removeElement
public boolean removeElement(Element arg0) throws java.lang.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:
removeElementin interfaceEhcache- Parameters:
arg0- 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)
-
removeAll
public void removeAll(boolean arg0) throws java.lang.IllegalStateException, CacheExceptionRemoves 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- Parameters:
arg0- 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_ALIVECacheException
-
removeAll
public void removeAll() throws java.lang.IllegalStateException, CacheExceptionRemoves 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- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException
-
removeAll
public void removeAll(java.util.Collection arg0, boolean arg1) throws java.lang.IllegalStateException, java.lang.NullPointerExceptionRemoves 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- Parameters:
arg0- a collection of keys to operate onarg1- 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_ALIVEjava.lang.NullPointerException
-
removeAll
public void removeAll(java.util.Collection arg0) throws java.lang.IllegalStateException, java.lang.NullPointerExceptionRemoves 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- Parameters:
arg0- a collection of keys to operate on- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVEjava.lang.NullPointerException- if any key is null in the collection
-
putIfAbsent
public Element putIfAbsent(Element arg0) throws java.lang.NullPointerException
Put an element in the cache if no element is currently mapped to the elements key.- Specified by:
putIfAbsentin interfaceEhcache- Parameters:
arg0- 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
-
putIfAbsent
public Element putIfAbsent(Element arg0, boolean arg1) throws java.lang.NullPointerException
Put an element in the cache if no element is currently mapped to the elements key.- Specified by:
putIfAbsentin interfaceEhcache- Parameters:
arg0- element to be addedarg1- 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
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener arg0)
Add a PropertyChangeListener.- Specified by:
addPropertyChangeListenerin interfaceEhcache- Parameters:
arg0- the listener to add
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener arg0)
Remove a PropertyChangeListener.- Specified by:
removePropertyChangeListenerin interfaceEhcache- Parameters:
arg0- the listener to remove
-
dispose
public void dispose() throws java.lang.IllegalStateExceptionFlushes all cache items from memory to auxilliary caches and close the auxilliary caches.Should be invoked only by CacheManager.
- Specified by:
disposein interfaceEhcache- Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVE
-
getKeys
public java.util.List getKeys() throws java.lang.IllegalStateException, CacheExceptionReturns 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). For large caches - or caches with high-latency storage this method can take a very long time to complete, may cause timeouts if using features such NonStopCache or transactions, and is not guaranteed to give a consistent view of the cache entry set. Usage is highly discouraged.
- Specified by:
getKeysin interfaceEhcache- Returns:
- a list of
Objectkeys - Throws:
java.lang.IllegalStateException- if the cache is notStatus.STATUS_ALIVECacheException
-
-