|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.ehcache.Cache
public class Cache
Cache is the central class in ehcache. Caches have Elements and are managed
by the CacheManager. The Cache performs logical actions. It delegates physical
implementations to its Stores.
CacheManager. A Cache thus obtained
is guaranteed to have status Status.STATUS_ALIVE. This status is checked for any method which
throws IllegalStateException and the same thrown if it is not alive. This would normally
happen if a call is made after CacheManager.shutdown() is invoked.
Cache is threadsafe.
Statistics on cache usage are collected and made available through the Cache.getStatistics() methods.
Various decorators are available for Cache, such as BlockingCache, SelfPopulatingCache and the dynamic proxy
ExceptionHandlingDynamicCacheProxy. See each class for details.

| Field Summary | |
|---|---|
static java.lang.String |
DEFAULT_CACHE_NAME
A reserved word for cache names. |
static long |
DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS
The default interval between runs of the expiry thread. |
static java.lang.String |
NET_SF_EHCACHE_DISABLED
System Property based method of disabling ehcache. |
| Constructor Summary | |
|---|---|
Cache(java.lang.String name,
int maxElementsInMemory,
boolean overflowToDisk,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds)
1.0 Constructor. |
|
Cache(java.lang.String name,
int maxElementsInMemory,
boolean overflowToDisk,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds)
1.1 Constructor. |
|
Cache(java.lang.String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
java.lang.String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners)
1.2 Constructor The ConfigurationFactory and clients can create these. |
|
Cache(java.lang.String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
java.lang.String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader)
1.2.1 Constructor The ConfigurationFactory and clients can create these. |
|
Cache(java.lang.String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
java.lang.String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader,
int maxElementsOnDisk)
1.2.4 Constructor The ConfigurationFactory and clients can create these. |
|
Cache(java.lang.String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
java.lang.String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader,
int maxElementsOnDisk,
int diskSpoolBufferSizeMB)
1.2.4 Constructor The ConfigurationFactory and clients can create these. |
|
| Method Summary | |
|---|---|
void |
bootstrap()
Bootstrap command. |
long |
calculateInMemorySize()
Gets the size of the memory store for this cache. |
void |
clearStatistics()
Resets statistics counters back to 0. |
java.lang.Object |
clone()
Clones a cache. |
protected Store |
createDiskStore()
Creates a disk store when either: overflowToDisk is enabled diskPersistent is enabled |
void |
dispose()
Starts an orderly shutdown of the Cache. |
boolean |
equals(java.lang.Object object)
An equals method which follows the contract of Object.equals(Object)
An Cache is equal to another one if it implements Ehcache and has the same GUID. |
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(java.lang.Object key)
Gets an element from the cache. |
Element |
get(java.io.Serializable key)
Gets an element from the cache. |
java.util.Map |
getAllWithLoader(java.util.Collection keys,
java.lang.Object loaderArgument)
Warning: This method is related to the JSR107 specification, which is in draft. |
float |
getAverageGetTime()
The average get time in ms. |
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()
Gets the ExceptionHandler on this Cache, or null if there isn't one. |
CacheLoader |
getCacheLoader()
Gets the CacheLoader registered in this cache |
CacheManager |
getCacheManager()
Gets the CacheManager managing this cache. |
long |
getDiskExpiryThreadIntervalSeconds()
Deprecated. Get this from the configuration |
int |
getDiskStoreHitCount()
Deprecated. Use Statistics |
int |
getDiskStoreSize()
Returns the number of elements in the disk store. |
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. |
int |
getHitCount()
Deprecated. Use Statistics |
java.util.List |
getKeys()
Returns a list of all element keys in the cache, whether or not they are expired. |
java.util.List |
getKeysNoDuplicateCheck()
Returns a list of all elements in the cache, whether or not they are expired. |
java.util.List |
getKeysWithExpiryCheck()
Returns a list of all element keys in the cache. |
int |
getMaxElementsInMemory()
Deprecated. Get this from the configuration |
int |
getMaxElementsOnDisk()
Deprecated. Get this from the configuration |
MemoryStoreEvictionPolicy |
getMemoryStoreEvictionPolicy()
Deprecated. Get this from the configuration |
int |
getMemoryStoreHitCount()
Deprecated. Use Statistics |
long |
getMemoryStoreSize()
Returns the number of elements in the memory store. |
int |
getMissCountExpired()
Deprecated. Use Statistics |
int |
getMissCountNotFound()
Deprecated. Use Statistics |
java.lang.String |
getName()
Gets the cache name. |
Element |
getQuiet(java.lang.Object key)
Gets an element from the cache, without updating Element statistics. |
Element |
getQuiet(java.io.Serializable key)
Gets an element from the cache, without updating Element statistics. |
int |
getSize()
Gets the size of the cache. |
Statistics |
getStatistics()
Gets an immutable Statistics object representing the Cache statistics at the time. Note, the Cache.getSize() method will have the same value as the size reported by Statistics
for the statistics accuracy of Statistics.STATISTICS_ACCURACY_BEST_EFFORT. |
int |
getStatisticsAccuracy()
Accurately measuring statistics can be expensive. |
Status |
getStatus()
Gets the status attribute of the Cache. |
long |
getTimeToIdleSeconds()
Deprecated. Get this from the configuration |
long |
getTimeToLiveSeconds()
Deprecated. Get this from the configuration |
Element |
getWithLoader(java.lang.Object key,
CacheLoader loader,
java.lang.Object loaderArgument)
Warning: This method is related to the JSR107 specification, which is in draft. |
int |
hashCode()
Returns a hash code value for the object. |
void |
initialise()
Newly created caches do not have a MemoryStore or a DiskStore. |
boolean |
isDisabled()
Whether this cache is disabled. |
boolean |
isDiskPersistent()
Deprecated. Get this from the configuration * |
protected boolean |
isDiskStore()
Whether this cache uses a disk store |
boolean |
isElementInMemory(java.lang.Object key)
Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval. |
boolean |
isElementInMemory(java.io.Serializable key)
Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval. |
boolean |
isElementOnDisk(java.lang.Object key)
Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval. |
boolean |
isElementOnDisk(java.io.Serializable key)
Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval. |
boolean |
isEternal()
Deprecated. Get this from the configuration |
boolean |
isExpired(Element element)
Checks whether this cache element has expired. |
boolean |
isKeyInCache(java.lang.Object key)
An inexpensive check to see if the key exists in the cache. |
boolean |
isOverflowToDisk()
Deprecated. Get this from the configuration |
boolean |
isValueInCache(java.lang.Object value)
An extremely expensive check to see if the value exists in the cache. |
void |
load(java.lang.Object key)
Warning: This method is related to the JSR107 specification, which is in draft. |
void |
loadAll(java.util.Collection keys,
java.lang.Object argument)
Warning: This method is related to the JSR107 specification, which is in draft. |
void |
put(Element element)
Put an element in the cache. |
void |
put(Element element,
boolean doNotNotifyCacheReplicators)
Put an element in the cache. |
void |
putQuiet(Element element)
Put an element in the cache, without updating statistics, or updating listeners. |
void |
registerCacheExtension(CacheExtension cacheExtension)
Register a CacheExtension with the cache. |
boolean |
remove(java.lang.Object key)
Removes an Element from the Cache. |
boolean |
remove(java.lang.Object key,
boolean doNotNotifyCacheReplicators)
Removes an Element from the Cache. |
boolean |
remove(java.io.Serializable key)
Removes an Element from the Cache. |
boolean |
remove(java.io.Serializable key,
boolean doNotNotifyCacheReplicators)
Removes an Element from the Cache. |
void |
removeAll()
Removes all cached items. |
void |
removeAll(boolean doNotNotifyCacheReplicators)
Removes all cached items. |
boolean |
removeQuiet(java.lang.Object key)
Removes an Element from the Cache, without notifying listeners. |
boolean |
removeQuiet(java.io.Serializable key)
Removes an Element from the Cache, without notifying listeners. |
void |
setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader)
Sets the bootstrap cache loader. |
void |
setCacheExceptionHandler(CacheExceptionHandler cacheExceptionHandler)
Sets an ExceptionHandler on the Cache. |
void |
setCacheLoader(CacheLoader cacheLoader)
Setter for the CacheLoader. |
void |
setCacheManager(CacheManager cacheManager)
For use by CacheManager. |
void |
setDisabled(boolean disabled)
Disables or enables this cache. |
void |
setDiskStorePath(java.lang.String diskStorePath)
DiskStore paths can conflict between CacheManager instances. |
void |
setName(java.lang.String name)
Sets the cache name which will name. |
void |
setStatisticsAccuracy(int statisticsAccuracy)
Sets the statistics accuracy. |
java.lang.String |
toString()
Returns a String representation of Cache. |
void |
unregisterCacheExtension(CacheExtension cacheExtension)
Unregister a CacheExtension with the cache. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String DEFAULT_CACHE_NAME
public static final java.lang.String NET_SF_EHCACHE_DISABLED
java -Dnet.sf.ehcache.disabled=true in the command line.
public static final long DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS
| Constructor Detail |
|---|
public Cache(java.lang.String name,
int maxElementsInMemory,
boolean overflowToDisk,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds)
ConfigurationFactory and clients can create these.
A client can specify their own settings here and pass the Cache object
into CacheManager.addCache(java.lang.String) to specify parameters other than the defaults.
Only the CacheManager can initialise them.
This constructor creates disk stores, if specified, that do not persist between restarts.
The default expiry thread interval of 120 seconds is used. This is the interval between runs
of the expiry thread, where it checks the disk store for expired elements. It is not the
the timeToLiveSeconds.
name - the name of the cache. Note that "default" is a reserved name for the defaultCache.maxElementsInMemory - the maximum number of elements in memory, before they are evictedoverflowToDisk - whether to use the disk storeeternal - whether the elements in the cache are eternal, i.e. never expiretimeToLiveSeconds - the default amount of time to live for an element from its creation datetimeToIdleSeconds - the default amount of time to live for an element from its last accessed or modified date
public Cache(java.lang.String name,
int maxElementsInMemory,
boolean overflowToDisk,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds)
ConfigurationFactory and clients can create these.
A client can specify their own settings here and pass the Cache object
into CacheManager.addCache(java.lang.String) to specify parameters other than the defaults.
Only the CacheManager can initialise them.
name - the name of the cache. Note that "default" is a reserved name for the defaultCache.maxElementsInMemory - the maximum number of elements in memory, before they are evictedoverflowToDisk - whether to use the disk storeeternal - whether the elements in the cache are eternal, i.e. never expiretimeToLiveSeconds - the default amount of time to live for an element from its creation datetimeToIdleSeconds - the default amount of time to live for an element from its last accessed or modified datediskPersistent - whether to persist the cache to disk between JVM restartsdiskExpiryThreadIntervalSeconds - how often to run the disk store expiry thread. A large number of 120 seconds plus is recommended
public Cache(java.lang.String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
java.lang.String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners)
ConfigurationFactory and clients can create these.
A client can specify their own settings here and pass the Cache object
into CacheManager.addCache(java.lang.String) to specify parameters other than the defaults.
Only the CacheManager can initialise them.
name - the name of the cache. Note that "default" is a reserved name for the defaultCache.maxElementsInMemory - the maximum number of elements in memory, before they are evictedmemoryStoreEvictionPolicy - one of LRU, LFU and FIFO. Optionally null, in which case it will be set to LRU.overflowToDisk - whether to use the disk storediskStorePath - this parameter is ignored. CacheManager sets it using setter injection.eternal - whether the elements in the cache are eternal, i.e. never expiretimeToLiveSeconds - the default amount of time to live for an element from its creation datetimeToIdleSeconds - the default amount of time to live for an element from its last accessed or modified datediskPersistent - whether to persist the cache to disk between JVM restartsdiskExpiryThreadIntervalSeconds - how often to run the disk store expiry thread. A large number of 120 seconds plus is recommendedregisteredEventListeners - a notification service. Optionally null, in which case a new
one with no registered listeners will be created.
public Cache(java.lang.String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
java.lang.String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader)
ConfigurationFactory and clients can create these.
A client can specify their own settings here and pass the Cache object
into CacheManager.addCache(java.lang.String) to specify parameters other than the defaults.
Only the CacheManager can initialise them.
name - the name of the cache. Note that "default" is a reserved name for the defaultCache.maxElementsInMemory - the maximum number of elements in memory, before they are evictedmemoryStoreEvictionPolicy - one of LRU, LFU and FIFO. Optionally null, in which case it will be set to LRU.overflowToDisk - whether to use the disk storediskStorePath - this parameter is ignored. CacheManager sets it using setter injection.eternal - whether the elements in the cache are eternal, i.e. never expiretimeToLiveSeconds - the default amount of time to live for an element from its creation datetimeToIdleSeconds - the default amount of time to live for an element from its last accessed or modified datediskPersistent - whether to persist the cache to disk between JVM restartsdiskExpiryThreadIntervalSeconds - how often to run the disk store expiry thread. A large number of 120 seconds plus is recommendedregisteredEventListeners - a notification service. Optionally null, in which case a new one with no registered listeners will be created.bootstrapCacheLoader - the BootstrapCacheLoader to use to populate the cache when it is first initialised. Null if none is required.
public Cache(java.lang.String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
java.lang.String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader,
int maxElementsOnDisk)
ConfigurationFactory and clients can create these.
A client can specify their own settings here and pass the Cache object
into CacheManager.addCache(java.lang.String) to specify parameters other than the defaults.
Only the CacheManager can initialise them.
name - the name of the cache. Note that "default" is a reserved name for the defaultCache.maxElementsInMemory - the maximum number of elements in memory, before they are evictedmemoryStoreEvictionPolicy - one of LRU, LFU and FIFO. Optionally null, in which case it will be set to LRU.overflowToDisk - whether to use the disk storediskStorePath - this parameter is ignored. CacheManager sets it using setter injection.eternal - whether the elements in the cache are eternal, i.e. never expiretimeToLiveSeconds - the default amount of time to live for an element from its creation datetimeToIdleSeconds - the default amount of time to live for an element from its last accessed or modified datediskPersistent - whether to persist the cache to disk between JVM restartsdiskExpiryThreadIntervalSeconds - how often to run the disk store expiry thread. A large number of 120 seconds plus is recommendedregisteredEventListeners - a notification service. Optionally null, in which case a new one with no registered listeners will be created.bootstrapCacheLoader - the BootstrapCacheLoader to use to populate the cache when it is first initialised. Null if none is required.
public Cache(java.lang.String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
java.lang.String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader,
int maxElementsOnDisk,
int diskSpoolBufferSizeMB)
ConfigurationFactory and clients can create these.
A client can specify their own settings here and pass the Cache object
into CacheManager.addCache(java.lang.String) to specify parameters other than the defaults.
Only the CacheManager can initialise them.
name - the name of the cache. Note that "default" is a reserved name for the defaultCache.maxElementsInMemory - the maximum number of elements in memory, before they are evictedmemoryStoreEvictionPolicy - one of LRU, LFU and FIFO. Optionally null, in which case it will be set to LRU.overflowToDisk - whether to use the disk storediskStorePath - this parameter is ignored. CacheManager sets it using setter injection.eternal - whether the elements in the cache are eternal, i.e. never expiretimeToLiveSeconds - the default amount of time to live for an element from its creation datetimeToIdleSeconds - the default amount of time to live for an element from its last accessed or modified datediskPersistent - whether to persist the cache to disk between JVM restartsdiskExpiryThreadIntervalSeconds - how often to run the disk store expiry thread. A large number of 120 seconds plus is recommendedregisteredEventListeners - a notification service. Optionally null, in which case a new one with no registered listeners will be created.bootstrapCacheLoader - the BootstrapCacheLoader to use to populate the cache when it is first initialised. Null if none is required.diskSpoolBufferSizeMB - the amount of memory to allocate the write buffer for puts to the DiskStore.| Method Detail |
|---|
public void initialise()
MemoryStore or a DiskStore.
This method creates those and makes the cache ready to accept elements
initialise in interface Ehcacheprotected Store createDiskStore()
protected boolean isDiskStore()
public void bootstrap()
bootstrap in interface Ehcache
public final void put(Element element)
throws java.lang.IllegalArgumentException,
java.lang.IllegalStateException,
CacheException
put in interface Ehcacheelement - An object. If Serializable it can fully participate in replication and the DiskStore.
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
java.lang.IllegalArgumentException - if the element is null
CacheException
public final void put(Element element,
boolean doNotNotifyCacheReplicators)
throws java.lang.IllegalArgumentException,
java.lang.IllegalStateException,
CacheException
put in interface Ehcacheelement - 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
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
java.lang.IllegalArgumentException - if the element is null
CacheException
public final void putQuiet(Element element)
throws java.lang.IllegalArgumentException,
java.lang.IllegalStateException,
CacheException
Cache.getQuiet(java.io.Serializable).
Synchronization is handled within the method.
Caches which use synchronous replication can throw RemoteCacheException here if the replication to the cluster fails.
This exception should be caught in those cirucmstances.
putQuiet in interface Ehcacheelement - An object. If Serializable it can fully participate in replication and the DiskStore.
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
java.lang.IllegalArgumentException - if the element is null
CacheException
public final Element get(java.io.Serializable key)
throws java.lang.IllegalStateException,
CacheException
Cache.getQuiet(Object) to peak into the Element to see its last access time with get
Synchronization is handled within the method.
get in interface Ehcachekey - a serializable value
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheExceptionCache.isExpired(net.sf.ehcache.Element)
public final Element get(java.lang.Object key)
throws java.lang.IllegalStateException,
CacheException
Cache.getQuiet(Object) to peak into the Element to see its last access time with get
Synchronization is handled within the method.
get in interface Ehcachekey - an Object value
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheExceptionCache.isExpired(net.sf.ehcache.Element)
public Element getWithLoader(java.lang.Object key,
CacheLoader loader,
java.lang.Object loaderArgument)
throws CacheException
getWithLoader in interface Ehcachekey - key whose associated value is to be returned.loader - the override loader to use. If null, the cache's default loader will be usedloaderArgument - an argument to pass to the CacheLoader.
CacheException
public void load(java.lang.Object key)
throws CacheException
SelfPopulatingCache
load in interface Ehcachekey - key whose associated value to be loaded using the associated cacheloader if this cache doesn't contain it.
CacheException
public java.util.Map getAllWithLoader(java.util.Collection keys,
java.lang.Object loaderArgument)
throws CacheException
SelfPopulatingCache
getAllWithLoader in interface Ehcachekeys - a collection of keys to be returned/loadedloaderArgument - an argument to pass to the CacheLoader.
CacheException
public void loadAll(java.util.Collection keys,
java.lang.Object argument)
throws CacheException
SelfPopulatingCache
loadAll in interface EhcacheCacheException
public final Element getQuiet(java.io.Serializable key)
throws java.lang.IllegalStateException,
CacheException
getQuiet in interface Ehcachekey - a serializable value
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheExceptionCache.isExpired(net.sf.ehcache.Element)
public final Element getQuiet(java.lang.Object key)
throws java.lang.IllegalStateException,
CacheException
getQuiet in interface Ehcachekey - a serializable value
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheExceptionCache.isExpired(net.sf.ehcache.Element)
public final java.util.List getKeys()
throws java.lang.IllegalStateException,
CacheException
getKeys in interface EhcacheObject keys
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public final java.util.List getKeysWithExpiryCheck()
throws java.lang.IllegalStateException,
CacheException
Cache.getKeys()
, which is synchronised, and which takes 8ms per 1000 entries. This way
cache liveness is preserved, even if this method is very slow to return.
Consider whether your usage requires checking for expired keys. Because
this method takes so long, depending on cache settings, the list could be
quite out of date by the time you get it.
getKeysWithExpiryCheck in interface EhcacheObject keys
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public final java.util.List getKeysNoDuplicateCheck()
throws java.lang.IllegalStateException
getKeysNoDuplicateCheck in interface EhcacheObject keys
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean remove(java.io.Serializable key)
throws java.lang.IllegalStateException
Element from the Cache. This also removes it from any
stores it may be in.
Also notifies the CacheEventListener after the element was removed.
Synchronization is handled within the method.
Caches which use synchronous replication can throw RemoteCacheException here if the replication to the cluster fails.
This exception should be caught in those cirucmstances.
remove in interface Ehcachekey - the element key to operate on
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean remove(java.lang.Object key)
throws java.lang.IllegalStateException
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.
Synchronization is handled within the method.
Caches which use synchronous replication can throw RemoteCacheException here if the replication to the cluster fails.
This exception should be caught in those cirucmstances.
remove in interface Ehcachekey - the element key to operate on
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean remove(java.io.Serializable key,
boolean doNotNotifyCacheReplicators)
throws java.lang.IllegalStateException
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.
Synchronization is handled within the method.
Caches which use synchronous replication can throw RemoteCacheException here if the replication to the cluster fails.
This exception should be caught in those cirucmstances.
remove in interface Ehcachekey - the element key to operate ondoNotNotifyCacheReplicators - whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a
further notification to doNotNotifyCacheReplicators cache peers
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean remove(java.lang.Object key,
boolean doNotNotifyCacheReplicators)
throws java.lang.IllegalStateException
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.
Synchronization is handled within the method.
remove in interface Ehcachekey - the element key to operate ondoNotNotifyCacheReplicators - whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a
further notification to doNotNotifyCacheReplicators cache peers
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean removeQuiet(java.io.Serializable key)
throws java.lang.IllegalStateException
Element from the Cache, without notifying listeners. This also removes it from any
stores it may be in.
Synchronization is handled within the method.
removeQuiet in interface Ehcachekey - the element key to operate on
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean removeQuiet(java.lang.Object key)
throws java.lang.IllegalStateException
Element from the Cache, without notifying listeners. This also removes it from any
stores it may be in.
Synchronization is handled within the method.
Caches which use synchronous replication can throw RemoteCacheException here if the replication to the cluster fails.
This exception should be caught in those cirucmstances.
removeQuiet in interface Ehcachekey - the element key to operate on
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
public void removeAll()
throws java.lang.IllegalStateException,
CacheException
removeAll in interface Ehcachejava.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public void removeAll(boolean doNotNotifyCacheReplicators)
throws java.lang.IllegalStateException,
CacheException
removeAll in interface EhcachedoNotNotifyCacheReplicators - 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
java.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public void dispose()
throws java.lang.IllegalStateException
dispose in interface Ehcachejava.lang.IllegalStateException - if the cache is already Status.STATUS_SHUTDOWNpublic CacheConfiguration getCacheConfiguration()
getCacheConfiguration in interface Ehcache
public final void flush()
throws java.lang.IllegalStateException,
CacheException
flush in interface Ehcachejava.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public final int getSize()
throws java.lang.IllegalStateException,
CacheException
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 Cache.getKeysWithExpiryCheck().size(),
although see that method for the approximate time that would take.
To get a very fast result, use Cache.getKeysNoDuplicateCheck().size(). If the disk store
is being used, there will be some duplicates.
getSize in interface Ehcachejava.lang.IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public final long calculateInMemorySize()
throws java.lang.IllegalStateException,
CacheException
calculateInMemorySize in interface Ehcachejava.lang.IllegalStateException
CacheException
public final long getMemoryStoreSize()
throws java.lang.IllegalStateException
getMemoryStoreSize in interface Ehcache