|
ehcache | |||||||||
| 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 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 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 String |
NET_SF_EHCACHE_DISABLED
System Property based method of disabling ehcache. |
static String |
NET_SF_EHCACHE_USE_CLASSIC_LRU
System Property based method of selecting the LruMemoryStore in use up to ehcache 1.5. |
| Constructor Summary | |
|---|---|
Cache(CacheConfiguration cacheConfiguration)
2.0 and higher Constructor The ConfigurationFactory and clients can create these. |
|
Cache(CacheConfiguration cacheConfiguration,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader)
2.0 and higher Constructor The ConfigurationFactory
and clients can create these. |
|
Cache(String name,
int maxElementsInMemory,
boolean overflowToDisk,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds)
1.0 Constructor. |
|
Cache(String name,
int maxElementsInMemory,
boolean overflowToDisk,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds)
1.1 Constructor. |
|
Cache(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
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(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
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(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
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(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader,
int maxElementsOnDisk,
int diskSpoolBufferSizeMB)
1.3 Constructor The ConfigurationFactory and clients can create these. |
|
Cache(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader,
int maxElementsOnDisk,
int diskSpoolBufferSizeMB,
boolean clearOnFlush)
1.6.0 Constructor The ConfigurationFactory and clients can create these. |
|
Cache(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader,
int maxElementsOnDisk,
int diskSpoolBufferSizeMB,
boolean clearOnFlush,
boolean isTerracottaClustered,
String terracottaValueMode,
boolean terracottaCoherentReads)
1.7.0 Constructor The ConfigurationFactory and clients can create these. |
|
| Method Summary | ||
|---|---|---|
void |
acquireReadLockOnKey(Object key)
Acquires the proper read lock for a given cache key |
|
void |
acquireWriteLockOnKey(Object key)
Acquires the proper write lock for a given cache key |
|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener. |
|
void |
bootstrap()
Bootstrap command. |
|
long |
calculateInMemorySize()
Gets the size of the memory store for this cache. |
|
long |
calculateOffHeapSize()
Gets the size of the off-heap store for this cache. |
|
void |
clearStatistics()
Resets statistics counters back to 0. |
|
Cache |
clone()
Clones a cache. |
|
void |
clusterCoherent(boolean clusterCoherent)
Inform of cluster coherence. |
|
protected DiskStore |
createDiskStore()
Creates a disk store when either: overflowToDisk is enabled diskPersistent is enabled |
|
Query |
createQuery()
Create a new query builder for this cache |
|
void |
disableDynamicFeatures()
Disables dynamic configuration and disable/enable for this cache. |
|
void |
dispose()
Starts an orderly shutdown of the Cache. |
|
boolean |
equals(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 |
firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
|
|
void |
flush()
Flushes all cache items from memory to the disk store, and from the DiskStore to disk. |
|
Element |
get(Object key)
Gets an element from the cache. |
|
Element |
get(Serializable key)
Gets an element from the cache. |
|
Map |
getAllWithLoader(Collection keys,
Object loaderArgument)
The getAll method will return, from the cache, a Map of the objects associated with the Collection of keys in argument "keys". |
|
float |
getAverageGetTime()
The average get time in ms. |
|
long |
getAverageSearchTime()
Get the average search execution time (in millis) for searches that have completed in the last sample period |
|
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. |
|
CacheManager |
getCacheManager()
Gets the CacheManager managing this cache. |
|
int |
getDiskStoreSize()
Returns the number of elements in the disk store. |
|
String |
getGuid()
The GUID for this cache instance can be used to determine whether two cache instance references are pointing to the same cache. |
|
Object |
getInternalContext()
This should not be used return some internal context (generally will be null) |
|
List |
getKeys()
Returns a list of all element keys in the cache, whether or not they are expired. |
|
List |
getKeysNoDuplicateCheck()
Returns a list of all elements in the cache, whether or not they are expired. |
|
List |
getKeysWithExpiryCheck()
Returns a list of all element keys in the cache. |
|
LiveCacheStatistics |
getLiveCacheStatistics()
This is different from Ehcache.getStatistics() in the way that values
returned from LiveCacheStatistics will reflect the current state
of the cache (and not a snapshot of the cache when the api's were called
like Ehcache.getStatistics()) |
|
protected Sync |
getLockForKey(Object key)
Gets the lock for a given key |
|
Policy |
getMemoryStoreEvictionPolicy()
|
|
long |
getMemoryStoreSize()
Returns the number of elements in the memory store. |
|
String |
getName()
Gets the cache name. |
|
long |
getOffHeapStoreSize()
Returns the number of elements in the off-heap store. |
|
Element |
getQuiet(Object key)
Gets an element from the cache, without updating Element statistics. |
|
Element |
getQuiet(Serializable key)
Gets an element from the cache, without updating Element statistics. |
|
List<CacheExtension> |
getRegisteredCacheExtensions()
|
|
List<CacheLoader> |
getRegisteredCacheLoaders()
|
|
CacheWriter |
getRegisteredCacheWriter()
Retrieves the CacheWriter that was registered for this cache. |
|
SampledCacheStatistics |
getSampledCacheStatistics()
Returns sampled statistics for this cache. |
|
|
getSearchAttribute(String attributeName)
Retrieve the given named search attribute |
|
long |
getSearchesPerSecond()
Get the number of search executions that have completed in the last second |
|
int |
getSize()
Gets the size of the cache. |
|
int |
getSizeBasedOnAccuracy(int statisticsAccuracy)
Accurately measuring statistics can be expensive. |
|
Statistics |
getStatistics()
Gets an immutable Statistics object representing the Cache statistics at the time. |
|
int |
getStatisticsAccuracy()
Accurately measuring statistics can be expensive. |
|
Status |
getStatus()
Gets the status attribute of the Cache. |
|
Object |
getStoreMBean()
Get the optional store management bean for this cache. |
|
TransactionManagerLookup |
getTransactionManagerLookup()
Get the TransactionManagerLookup implementation used to lookup the TransactionManager. |
|
Element |
getWithLoader(Object key,
CacheLoader loader,
Object loaderArgument)
This method will return, from the cache, the Element associated with the argument "key". |
|
CacheWriterManager |
getWriterManager()
Obtain the writer manager that's used by this cache instance. |
|
int |
hashCode()
Returns a hash code value for the object. |
|
void |
initialise()
Newly created caches do not have a Store. |
|
boolean |
isClusterBulkLoadEnabled()
Returns true if at least one node in the cluster is in bulk-load mode. |
|
boolean |
isClusterCoherent()
Deprecated. use isClusterBulkLoadEnabled() instead |
|
boolean |
isDisabled()
Whether this cache is disabled. |
|
protected boolean |
isDiskStore()
Whether this cache uses a disk store |
|
boolean |
isElementInMemory(Object key)
Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval. |
|
boolean |
isElementInMemory(Serializable key)
Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval. |
|
boolean |
isElementOffHeap(Object key)
Whether an Element is stored in the cache in off-heap memory, indicating an intermediate cost of retrieval. |
|
boolean |
isElementOnDisk(Object key)
Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval. |
|
boolean |
isElementOnDisk(Serializable key)
Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval. |
|
boolean |
isExpired(Element element)
Checks whether this cache element has expired. |
|
boolean |
isKeyInCache(Object key)
An inexpensive check to see if the key exists in the cache. |
|
boolean |
isNodeBulkLoadEnabled()
Returns true if the current node is in bulk-load mode. |
|
boolean |
isNodeCoherent()
Deprecated. use isNodeBulkLoadEnabled() instead |
|
boolean |
isReadLockedByCurrentThread(Object key)
Returns true if a read lock for the key is held by the current thread |
|
boolean |
isSampledStatisticsEnabled()
Returns if sampled statistics collection is enabled or disabled |
|
boolean |
isSearchable()
Is this cache searchable? |
|
boolean |
isStatisticsEnabled()
Returns true if statistics collection is enabled |
|
boolean |
isTerracottaClustered()
Indicates whether this cache is clustered by Terracotta |
|
boolean |
isValueInCache(Object value)
An extremely expensive check to see if the value exists in the cache. |
|
boolean |
isWriteLockedByCurrentThread(Object key)
Returns true if a write lock for the key is held by the current thread |
|
void |
load(Object key)
The load method provides a means to "pre load" the cache. |
|
void |
loadAll(Collection keys,
Object argument)
The loadAll method provides a means to "pre load" objects into the cache. |
|
void |
put(Element element)
Put an element in the cache. |
|
void |
put(Element element,
boolean doNotNotifyCacheReplicators)
Put an element in the cache. |
|
Element |
putIfAbsent(Element element)
Put an element in the cache if no element is currently mapped to the elements key. |
|
void |
putQuiet(Element element)
Put an element in the cache, without updating statistics, or updating listeners. |
|
void |
putWithWriter(Element element)
Put an element in the cache writing through a CacheWriter. |
|
void |
registerCacheExtension(CacheExtension cacheExtension)
Register a CacheExtension with the cache. |
|
void |
registerCacheLoader(CacheLoader cacheLoader)
Register a CacheLoader with the cache. |
|
void |
registerCacheUsageListener(CacheUsageListener cacheUsageListener)
Registers a CacheUsageListener which will be notified of the
cache
usage. |
|
void |
registerCacheWriter(CacheWriter cacheWriter)
Register the CacheWriter for this cache. |
|
void |
releaseReadLockOnKey(Object key)
Release a held read lock for the passed in key |
|
void |
releaseWriteLockOnKey(Object key)
Release a held write lock for the passed in key |
|
boolean |
remove(Object key)
Removes an Element from the Cache. |
|
boolean |
remove(Object key,
boolean doNotNotifyCacheReplicators)
Removes an Element from the Cache. |
|
boolean |
remove(Serializable key)
Removes an Element from the Cache. |
|
boolean |
remove(Serializable key,
boolean doNotNotifyCacheReplicators)
Removes an Element from the Cache. |
|
void |
removeAll()
Removes all cached items. |
|
void |
removeAll(boolean doNotNotifyCacheReplicators)
Removes all cached items. |
|
void |
removeCacheUsageListener(CacheUsageListener cacheUsageListener)
Remove an already registered CacheUsageListener, if any. |
|
boolean |
removeElement(Element element)
Remove the Element mapped to the key for the supplied element if the value of the supplied Element is equal to the value of the cached Element. |
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener. |
|
boolean |
removeQuiet(Object key)
Removes an Element from the Cache, without notifying listeners. |
|
boolean |
removeQuiet(Serializable key)
Removes an Element from the Cache, without notifying listeners. |
|
boolean |
removeWithWriter(Object key)
Removes an Element from the Cache and any stores it might be in. |
|
Element |
replace(Element element)
Replace the cached element only if an Element is currently cached for this key |
|
boolean |
replace(Element old,
Element element)
Replace the cached element only if the current Element is equal to the supplied old Element. |
|
void |
setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader)
Sets the bootstrap cache loader. |
|
void |
setCacheExceptionHandler(CacheExceptionHandler cacheExceptionHandler)
Sets an ExceptionHandler on the Cache. |
|
void |
setCacheManager(CacheManager cacheManager)
For use by CacheManager. |
|
void |
setDisabled(boolean disabled)
Disables or enables this cache. |
|
void |
setDiskStorePath(String diskStorePath)
DiskStore paths can conflict between CacheManager instances. |
|
void |
setMemoryStoreEvictionPolicy(Policy policy)
Sets the eviction policy strategy. |
|
void |
setName(String name)
Sets the cache name which will name. |
|
void |
setNodeBulkLoadEnabled(boolean enabledBulkLoad)
Enable/disable bulk-load mode in this node for this cache. |
|
void |
setNodeCoherent(boolean coherent)
Deprecated. use setNodeBulkLoadEnabled(boolean) instead |
|
void |
setSampledStatisticsEnabled(boolean enableStatistics)
Enable/disable sampled statistics collection. |
|
void |
setStatisticsAccuracy(int statisticsAccuracy)
Sets the statistics accuracy. |
|
void |
setStatisticsEnabled(boolean enableStatistics)
Enable/disable statistics collection. |
|
void |
setTransactionManagerLookup(TransactionManagerLookup lookup)
Sets the TransactionManagerLookup that needs to be used for this cache to lookup the TransactionManager This needs to be set before initialise() is called |
|
String |
toString()
Returns a String representation of Cache. |
|
boolean |
tryReadLockOnKey(Object key,
long timeout)
Try to get a read lock on a given key. |
|
boolean |
tryWriteLockOnKey(Object key,
long timeout)
Try to get a write lock on a given key. |
|
void |
unregisterCacheExtension(CacheExtension cacheExtension)
Unregister a CacheExtension with the cache. |
|
void |
unregisterCacheLoader(CacheLoader cacheLoader)
Unregister a CacheLoader with the cache. |
|
void |
unregisterCacheWriter()
Unregister the CacheWriter from the cache. |
|
void |
waitUntilClusterBulkLoadComplete()
This method waits until all the connected nodes have disabled bulk-load. |
|
void |
waitUntilClusterCoherent()
Deprecated. use waitUntilClusterBulkLoadComplete() instead |
|
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String DEFAULT_CACHE_NAME
public static final String NET_SF_EHCACHE_DISABLED
java -Dnet.sf.ehcache.disabled=true in the command line.
public static final String NET_SF_EHCACHE_USE_CLASSIC_LRU
java -Dnet.sf.ehcache.use.classic.lru=true in the command line.
public static final long DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS
CacheConfiguration#DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS for a preferred way of setting,
Constant Field Values| Constructor Detail |
|---|
public Cache(CacheConfiguration cacheConfiguration)
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.
cacheConfiguration - the configuration that should be used to create the cache with
public Cache(CacheConfiguration cacheConfiguration,
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.
cacheConfiguration - the configuration that should be used to create the cache withregisteredEventListeners - 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(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 evicted (0 == no limit)overflowToDisk - 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 dateCache(CacheConfiguration, RegisteredEventListeners, BootstrapCacheLoader),
for full construction support of version 2.0 and higher features.
public Cache(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 evicted (0 == no limit)overflowToDisk - 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 recommendedCache(CacheConfiguration, RegisteredEventListeners, BootstrapCacheLoader),
for full construction support of version 2.0 and higher features.
public Cache(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
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 evicted (0 == no limit)memoryStoreEvictionPolicy - 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.Cache(CacheConfiguration, RegisteredEventListeners, BootstrapCacheLoader),
for full construction support of version 2.0 and higher features.
public Cache(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
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 evicted (0 == no limit)memoryStoreEvictionPolicy - 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.Cache(CacheConfiguration, RegisteredEventListeners, BootstrapCacheLoader),
for full construction support of version 2.0 and higher features.
public Cache(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
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 evicted (0 == no limit)memoryStoreEvictionPolicy - 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.maxElementsOnDisk - the maximum number of Elements to allow on the disk. 0 means unlimited.Cache(CacheConfiguration, RegisteredEventListeners, BootstrapCacheLoader),
for full construction support of version 2.0 and higher features.
public Cache(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
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 evicted (0 == no limit)memoryStoreEvictionPolicy - 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.maxElementsOnDisk - the maximum number of Elements to allow on the disk. 0 means unlimited.diskSpoolBufferSizeMB - the amount of memory to allocate the write buffer for puts to the DiskStore.Cache(CacheConfiguration, RegisteredEventListeners, BootstrapCacheLoader),
for full construction support of version 2.0 and higher features.
public Cache(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader,
int maxElementsOnDisk,
int diskSpoolBufferSizeMB,
boolean clearOnFlush)
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 evicted (0 == no limit)memoryStoreEvictionPolicy - 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.maxElementsOnDisk - the maximum number of Elements to allow on the disk. 0 means unlimited.diskSpoolBufferSizeMB - the amount of memory to allocate the write buffer for puts to the DiskStore.clearOnFlush - whether the in-memory storage should be cleared when flush() is called on the cacheCache(CacheConfiguration, RegisteredEventListeners, BootstrapCacheLoader),
for full construction support of version 2.0 and higher features.
public Cache(String name,
int maxElementsInMemory,
MemoryStoreEvictionPolicy memoryStoreEvictionPolicy,
boolean overflowToDisk,
String diskStorePath,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds,
boolean diskPersistent,
long diskExpiryThreadIntervalSeconds,
RegisteredEventListeners registeredEventListeners,
BootstrapCacheLoader bootstrapCacheLoader,
int maxElementsOnDisk,
int diskSpoolBufferSizeMB,
boolean clearOnFlush,
boolean isTerracottaClustered,
String terracottaValueMode,
boolean terracottaCoherentReads)
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 evicted (0 == no limit)memoryStoreEvictionPolicy - 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.maxElementsOnDisk - the maximum number of Elements to allow on the disk. 0 means unlimited.diskSpoolBufferSizeMB - the amount of memory to allocate the write buffer for puts to the DiskStore.clearOnFlush - whether the in-memory storage should be cleared when flush() is called on the cacheisTerracottaClustered - whether to cluster this cache with TerracottaterracottaValueMode - either "SERIALIZATION" or "IDENTITY" mode, only used if isTerracottaClustered=trueterracottaCoherentReads - whether this cache should use coherent reads (usually should be true) unless optimizing for read-onlyCache(CacheConfiguration, RegisteredEventListeners, BootstrapCacheLoader),
for full construction support of version 2.0 and higher features.| Method Detail |
|---|
public TransactionManagerLookup getTransactionManagerLookup()
TransactionManagerLookup instancepublic void setTransactionManagerLookup(TransactionManagerLookup lookup)
initialise() is called
setTransactionManagerLookup in interface Ehcachelookup - The TransactionManagerLookup instancepublic void initialise()
Store.
This method creates the store and makes the cache ready to accept elements
initialise in interface Ehcachepublic CacheWriterManager getWriterManager()
getWriterManager in interface Ehcacheprotected DiskStore createDiskStore()
protected boolean isDiskStore()
public boolean isTerracottaClustered()
true when the cache is clustered by Terracotta; or false otherwisepublic void bootstrap()
bootstrap in interface Ehcache
public final void put(Element element)
throws IllegalArgumentException,
IllegalStateException,
CacheException
put in interface Ehcacheelement - A cache Element. If Serializable it can fully participate in replication and the DiskStore. If it is
null or the key is null, it is ignored as a NOOP.
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
IllegalArgumentException - if the element is null
public final void put(Element element,
boolean doNotNotifyCacheReplicators)
throws IllegalArgumentException,
IllegalStateException,
CacheException
put in interface Ehcacheelement - A cache Element. If Serializable it can fully participate in replication and the DiskStore. If it is
null or the key is null, it is ignored as a NOOP.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
IllegalStateException - if the cache is not Status.STATUS_ALIVE
IllegalArgumentException - if the element is null
CacheException
public void putWithWriter(Element element)
throws IllegalArgumentException,
IllegalStateException,
CacheException
putWithWriter in interface Ehcacheelement - An object. If Serializable it can fully participate in replication and the DiskStore.
IllegalArgumentException - if the element is null
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException - if no CacheWriter was registered
public final void putQuiet(Element element)
throws IllegalArgumentException,
IllegalStateException,
CacheException
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 circumstances.
putQuiet in interface Ehcacheelement - A cache Element. If Serializable it can fully participate in replication and the DiskStore. If it is
null or the key is null, it is ignored as a NOOP.
IllegalStateException - if the cache is not Status.STATUS_ALIVE
IllegalArgumentException - if the element is null
CacheException
public final Element get(Serializable key)
throws IllegalStateException,
CacheException
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. Null keys are not stored so get(null) always returns null
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheExceptionisExpired(net.sf.ehcache.Element)
public final Element get(Object key)
throws IllegalStateException,
CacheException
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
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheExceptionisExpired(net.sf.ehcache.Element)
public Element getWithLoader(Object key,
CacheLoader loader,
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(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 Map getAllWithLoader(Collection keys,
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(Collection keys,
Object argument)
throws CacheException
SelfPopulatingCache
loadAll in interface EhcacheCacheException
public final Element getQuiet(Serializable key)
throws IllegalStateException,
CacheException
getQuiet in interface Ehcachekey - a serializable value
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheExceptionisExpired(net.sf.ehcache.Element)
public final Element getQuiet(Object key)
throws IllegalStateException,
CacheException
getQuiet in interface Ehcachekey - a serializable value
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheExceptionisExpired(net.sf.ehcache.Element)
public final List getKeys()
throws IllegalStateException,
CacheException
getKeys in interface EhcacheObject keys
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public final List getKeysWithExpiryCheck()
throws IllegalStateException,
CacheException
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
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public final List getKeysNoDuplicateCheck()
throws IllegalStateException
getKeysNoDuplicateCheck in interface EhcacheObject keys
IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean remove(Serializable key)
throws 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 circumstances.
remove in interface Ehcachekey - the element key to operate on
IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean remove(Object key)
throws 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 circumstances.
remove in interface Ehcachekey - the element key to operate on
IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean remove(Serializable key,
boolean doNotNotifyCacheReplicators)
throws 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 circumstances.
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
IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean remove(Object key,
boolean doNotNotifyCacheReplicators)
throws 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
IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean removeQuiet(Serializable key)
throws IllegalStateException
Element from the Cache, without notifying listeners. This also removes it from any
stores it may be in.
Listeners are not called.
removeQuiet in interface Ehcachekey - the element key to operate on
IllegalStateException - if the cache is not Status.STATUS_ALIVE
public final boolean removeQuiet(Object key)
throws IllegalStateException
Element from the Cache, without notifying listeners. This also removes it from any
stores it may be in.
Listeners are not called.
Caches which use synchronous replication can throw RemoteCacheException here if the replication to the cluster fails.
This exception should be caught in those circumstances.
removeQuiet in interface Ehcachekey - the element key to operate on
IllegalStateException - if the cache is not Status.STATUS_ALIVE
public boolean removeWithWriter(Object key)
throws IllegalStateException
Element from the Cache and any stores it might be in. This also removes through
to a CacheWriter. If no CacheWriter has been registered for the cache, then this method throws an exception.
Also notifies the CacheEventListener after the element was removed, but only if an Element
with the key actually existed.
removeWithWriter in interface EhcacheIllegalStateException - if the cache is not Status.STATUS_ALIVE
public void removeAll()
throws IllegalStateException,
CacheException
removeAll in interface EhcacheIllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public void removeAll(boolean doNotNotifyCacheReplicators)
throws 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
IllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public void dispose()
throws IllegalStateException
dispose in interface EhcacheIllegalStateException - if the cache is already Status.STATUS_SHUTDOWNpublic CacheConfiguration getCacheConfiguration()
getCacheConfiguration in interface Ehcache
public final void flush()
throws IllegalStateException,
CacheException
flush in interface EhcacheIllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public final int getSize()
throws IllegalStateException,
CacheException
getKeysWithExpiryCheck().size(), although see that method for
the approximate time that would take.
To get a very fast result, use 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.
getSize in interface EhcacheIllegalStateException - if the cache is not Status.STATUS_ALIVE
CacheException
public int getSizeBasedOnAccuracy(int statisticsAccuracy)
throws IllegalStateException,
CacheException
getSizeBasedOnAccuracy in interface EhcachestatisticsAccuracy - one of Statistics.STATISTICS_ACCURACY_BEST_EFFORT,
Statistics.STATISTICS_ACCURACY_GUARANTEED,
Statistics.STATISTICS_ACCURACY_NONE
IllegalStateException - if the cache is not
Status.STATUS_ALIVE
CacheException
public final long calculateInMemorySize()
throws IllegalStateException,
CacheException
calculateInMemorySize in interface EhcacheIllegalStateException
CacheException
public final long calculateOffHeapSize()
throws IllegalStateException,
CacheException
calculateOffHeapSize in interface EhcacheIllegalStateException
CacheException
public final long getMemoryStoreSize()
throws IllegalStateException
getMemoryStoreSize in interface EhcacheIllegalStateException - if the cache is not Status.STATUS_ALIVE
public long getOffHeapStoreSize()
throws IllegalStateException
getOffHeapStoreSize in interface EhcacheIllegalStateException - if the cache is not Status.STATUS_ALIVE
public final int getDiskStoreSize()
throws IllegalStateException
getDiskStoreSize in interface EhcacheIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic final Status getStatus()
getStatus in interface Ehcachepublic final String getName()
getName in interface Ehcache
public final void setName(String name)
throws IllegalArgumentException
setName in interface Ehcachename - the name of the cache. Should not be null. Should also not contain any '/' characters, as these interfere
with distribution
IllegalArgumentException - if an illegal name is used.public String toString()
String representation of Cache.
toString in interface EhcachetoString in class Object
public final boolean isExpired(Element element)
throws IllegalStateException,
NullPointerException
isExpired in interface Ehcacheelement - the element to check
IllegalStateException - if the cache is not Status.STATUS_ALIVE
NullPointerException - if the element is null
todo this does not need to be synchronized
public final Cache clone()
throws CloneNotSupportedException
clone in interface Ehcacheclone in class ObjectCache
CloneNotSupportedExceptionpublic final Object getStoreMBean()
public final RegisteredEventListeners getCacheEventNotificationService()
getCacheEventNotificationService in interface Ehcachepublic final boolean isElementInMemory(Serializable key)
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.
isElementInMemory in interface Ehcachepublic final boolean isElementInMemory(Object key)
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.
isElementInMemory in interface Ehcachepublic final boolean isElementOffHeap(Object key)
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.
public final boolean isElementOnDisk(Serializable key)
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.
isElementOnDisk in interface Ehcachepublic final boolean isElementOnDisk(Object key)
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.
isElementOnDisk in interface Ehcachepublic final String getGuid()
getGuid in interface Ehcachepublic final CacheManager getCacheManager()
getCacheManager in interface Ehcache
public void clearStatistics()
throws IllegalStateException
clearStatistics in interface EhcacheIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic int getStatisticsAccuracy()
getStatisticsAccuracy in interface EhcacheStatistics.STATISTICS_ACCURACY_BEST_EFFORT, Statistics.STATISTICS_ACCURACY_GUARANTEED, Statistics.STATISTICS_ACCURACY_NONEpublic void setStatisticsAccuracy(int statisticsAccuracy)
setStatisticsAccuracy in interface EhcachestatisticsAccuracy - one of Statistics.STATISTICS_ACCURACY_BEST_EFFORT, Statistics.STATISTICS_ACCURACY_GUARANTEED, Statistics.STATISTICS_ACCURACY_NONEpublic void evictExpiredElements()
evictExpiredElements in interface Ehcachepublic boolean isKeyInCache(Object key)
isKeyInCache in interface Ehcachekey - the key to check.
public boolean isValueInCache(Object value)
isValueInCache in interface Ehcachevalue - to check for
public Statistics getStatistics()
throws IllegalStateException
Statistics.STATISTICS_ACCURACY_BEST_EFFORT.
The size is the number of Elements in the MemoryStore plus
the number of Elements in the DiskStore.
This number is the actual number of elements, including expired elements that have
not been removed. Any duplicates between stores are accounted for.
Expired elements are removed from the the memory store when
getting an expired element, or when attempting to spool an expired element to
disk.
Expired elements are removed from the disk store when getting an expired element,
or when the expiry thread runs, which is once every five minutes.
Statistics.STATISTICS_ACCURACY_GUARANTEED.
This method accounts for elements which might be expired or duplicated between stores. It take approximately
200ms per 1000 elements to execute.
Statistics.STATISTICS_ACCURACY_NONE.
The number given may contain expired elements. In addition if the DiskStore is used it may contain some double
counting of elements. It takes 6ms for 1000 elements to execute. Time to execute is O(log n). 50,000 elements take
36ms.
Note, the getSize() method will have the same value as the size
reported by Statistics for the statistics accuracy of
Statistics.STATISTICS_ACCURACY_BEST_EFFORT.
getStatistics in interface EhcacheIllegalStateException - if the cache is not Status.STATUS_ALIVEpublic long getAverageSearchTime()
getAverageSearchTime in interface Ehcachepublic long getSearchesPerSecond()
getSearchesPerSecond in interface Ehcachepublic void setCacheManager(CacheManager cacheManager)
setCacheManager in interface EhcachecacheManager - the CacheManager for this cache to use.public BootstrapCacheLoader getBootstrapCacheLoader()
getBootstrapCacheLoader in interface Ehcache
public void setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader)
throws CacheException
setBootstrapCacheLoader in interface EhcachebootstrapCacheLoader - the loader to be used
CacheException - if this method is called after the cache is initialized
public void setDiskStorePath(String diskStorePath)
throws CacheException
setDiskStorePath in interface EhcachediskStorePath - the new path to be used.
CacheException - if this method is called after the cache is initializedpublic boolean equals(Object object)
Object.equals(Object)
An Cache is equal to another one if it implements Ehcache and has the same GUID.
equals in class Objectobject - the reference object with which to compare.
true if this object is the same as the obj
argument; false otherwise.hashCode(),
Hashtablepublic int hashCode()
java.util.Hashtable.
The general contract of hashCode is:
hashCode method on each of
the two objects must produce the same integer result.
Object.equals(Object)
method, then calling the hashCode method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hashtables.
hashCode in class ObjectObject.equals(Object),
Hashtablepublic void registerCacheExtension(CacheExtension cacheExtension)
CacheExtension with the cache. It will then be tied into the cache lifecycle.
If the CacheExtension is not initialised, initialise it.
registerCacheExtension in interface Ehcachepublic List<CacheExtension> getRegisteredCacheExtensions()
getRegisteredCacheExtensions in interface Ehcachepublic void unregisterCacheExtension(CacheExtension cacheExtension)
CacheExtension with the cache. It will then be detached from the cache lifecycle.
unregisterCacheExtension in interface Ehcachepublic float getAverageGetTime()
getAverageGetTime in interface Ehcachepublic void setCacheExceptionHandler(CacheExceptionHandler cacheExceptionHandler)
ExceptionHandlingDynamicCacheProxy.
setCacheExceptionHandler in interface EhcacheExceptionHandlingDynamicCacheProxypublic CacheExceptionHandler getCacheExceptionHandler()
ExceptionHandlingDynamicCacheProxy.
getCacheExceptionHandler in interface EhcacheExceptionHandlingDynamicCacheProxypublic void registerCacheLoader(CacheLoader cacheLoader)
CacheLoader with the cache. It will then be tied into the cache lifecycle.
If the CacheLoader is not initialised, initialise it.
registerCacheLoader in interface EhcachecacheLoader - A Cache Loader to registerpublic void unregisterCacheLoader(CacheLoader cacheLoader)
CacheLoader with the cache. It will then be detached from the cache lifecycle.
unregisterCacheLoader in interface EhcachecacheLoader - A Cache Loader to unregisterpublic List<CacheLoader> getRegisteredCacheLoaders()
getRegisteredCacheLoaders in interface Ehcachepublic void registerCacheWriter(CacheWriter cacheWriter)
CacheWriter for this cache. It will then be tied into the cache lifecycle.
If the CacheWriter is not initialised, initialise it.
registerCacheWriter in interface EhcachecacheWriter - A CacheWriter to registerpublic void unregisterCacheWriter()
CacheWriter from the cache. It will then be detached from the cache lifecycle.
If not CacheWriter was registered beforehand this operation has no effect.
unregisterCacheWriter in interface Ehcachepublic CacheWriter getRegisteredCacheWriter()
CacheWriter that was registered for this cache.
getRegisteredCacheWriter in interface EhcacheCacheWriter; or null if none was registered beforepublic boolean isDisabled()
setDisabled(boolean) method.
By default caches are enabled on creation, unless the net.sf.ehcache.disabled system
property is set.
isDisabled in interface Ehcache?public void setDisabled(boolean disabled)
net.sf.ehcache.disabled system property is set
setDisabled in interface Ehcachedisabled - true if you wish to disable, false to enableisDisabled()public Policy getMemoryStoreEvictionPolicy()
public void setMemoryStoreEvictionPolicy(Policy policy)
policy - the new policy
public LiveCacheStatistics getLiveCacheStatistics()
throws IllegalStateException
Ehcache.getStatistics() in the way that values
returned from LiveCacheStatistics will reflect the current state
of the cache (and not a snapshot of the cache when the api's were called
like Ehcache.getStatistics())
getLiveCacheStatistics in interface EhcacheLiveCacheStatistics associated with this cache
IllegalStateException
public void registerCacheUsageListener(CacheUsageListener cacheUsageListener)
throws IllegalStateException
CacheUsageListener which will be notified of the
cache
usage.
Implementations of CacheUsageListener should override the
Object.equals(Object) and Object.hashCode() methods as it is used for
equality check
registerCacheUsageListener in interface EhcacheIllegalStateException
public void removeCacheUsageListener(CacheUsageListener cacheUsageListener)
throws IllegalStateException
CacheUsageListener, if any.
Depends on the Object.equals(Object) method.
removeCacheUsageListener in interface EhcacheIllegalStateExceptionpublic boolean isStatisticsEnabled()
isStatisticsEnabled in interface Ehcachepublic void setStatisticsEnabled(boolean enableStatistics)
Ehcache.setSampledStatisticsEnabled(boolean) with
parameter true.
Disabling statistics also disables the sampled statistics collection if
it is enabled
setStatisticsEnabled in interface Ehcachepublic SampledCacheStatistics getSampledCacheStatistics()
getSampledCacheStatistics in interface Ehcachepublic void setSampledStatisticsEnabled(boolean enableStatistics)
setSampledStatisticsEnabled in interface Ehcachepublic boolean isSampledStatisticsEnabled()
isSampledStatisticsEnabled in interface EhcacheEhcache.isSampledStatisticsEnabled()public Object getInternalContext()
getInternalContext in interface Ehcachepublic void disableDynamicFeatures()
This is a one time operation. Once an Ehcache instance has had its dynamic operations disabled they cannot be re-enabled.
disableDynamicFeatures in interface Ehcache@Deprecated public boolean isClusterCoherent()
isClusterBulkLoadEnabled() instead
isClusterCoherent in interface Ehcache@Deprecated public boolean isNodeCoherent()
isNodeBulkLoadEnabled() instead
isNodeCoherent in interface Ehcache@Deprecated public void setNodeCoherent(boolean coherent)
setNodeBulkLoadEnabled(boolean) instead
setNodeCoherent(true) when the cache is already in coherent mode or
calling setNodeCoherent(false) when already in incoherent mode will be a no-op.
It applies to coherent clustering mechanisms only e.g. Terracotta
When using Terracotta clustered caches with nonstop enabled, the timeout used by this method is
NonstopConfiguration.getBulkOpsTimeoutMultiplyFactor() times the timeout value in the config.
setNodeCoherent in interface Ehcachecoherent - true transitions to coherent mode, false to incoherent mode@Deprecated public void waitUntilClusterCoherent()
waitUntilClusterBulkLoadComplete() instead
waitUntilClusterCoherent in interface Ehcachepublic void addPropertyChangeListener(PropertyChangeListener listener)
Ehcache
addPropertyChangeListener in interface Ehcachelistener - public void removePropertyChangeListener(PropertyChangeListener listener)
Ehcache
removePropertyChangeListener in interface Ehcachelistener -
public void firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
propertyName - oldValue - newValue -
public Element putIfAbsent(Element element)
throws NullPointerException
putIfAbsent in interface Ehcacheelement - element to be added
NullPointerException - if the element is null, or has a null key
public boolean removeElement(Element element)
throws NullPointerException
removeElement in interface Ehcacheelement - Element to be removed
NullPointerException - if the element is null, or has a null key
public boolean replace(Element old,
Element element)
throws NullPointerException,
IllegalArgumentException
replace in interface Ehcacheold - Element to be test againstelement - Element to be cached
NullPointerException - if the either Element is null or has a null key
IllegalArgumentException - if the two Element keys are non-null but not equal
public Element replace(Element element)
throws NullPointerException
replace in interface Ehcacheelement - Element to be cached
NullPointerException - if the Element is null or has a null keypublic void clusterCoherent(boolean clusterCoherent)
clusterCoherent in interface StoreListenerStoreListener.clusterCoherent(boolean)
public <T> Attribute<T> getSearchAttribute(String attributeName)
throws CacheException
getSearchAttribute in interface EhcacheT - type of the attributeattributeName - the name of the attribute to retrieve
CacheException - if no such attribute is defined for the given namepublic Query createQuery()
createQuery in interface Ehcachepublic boolean isSearchable()
isSearchable in interface Ehcacheprotected Sync getLockForKey(Object key)
key -
public void acquireReadLockOnKey(Object key)
acquireReadLockOnKey in interface Ehcachekey - - The key that retrieves a value that you want to protect via lockingpublic void acquireWriteLockOnKey(Object key)
acquireWriteLockOnKey in interface Ehcachekey - - The key that retrieves a value that you want to protect via locking
public boolean tryReadLockOnKey(Object key,
long timeout)
throws InterruptedException
tryReadLockOnKey in interface Ehcachekey - - The key that retrieves a value that you want to protect via lockingtimeout - - millis until giveup on getting the lock
InterruptedException
public boolean tryWriteLockOnKey(Object key,
long timeout)
throws InterruptedException
tryWriteLockOnKey in interface Ehcachekey - - The key that retrieves a value that you want to protect via lockingtimeout - - millis until giveup on getting the lock
InterruptedExceptionpublic void releaseReadLockOnKey(Object key)
releaseReadLockOnKey in interface Ehcachekey - - The key that retrieves a value that you want to protect via lockingpublic void releaseWriteLockOnKey(Object key)
releaseWriteLockOnKey in interface Ehcachekey - - The key that retrieves a value that you want to protect via lockingpublic boolean isReadLockedByCurrentThread(Object key)
isReadLockedByCurrentThread in interface Ehcachepublic boolean isWriteLockedByCurrentThread(Object key)
isWriteLockedByCurrentThread in interface Ehcache
public boolean isClusterBulkLoadEnabled()
throws UnsupportedOperationException,
TerracottaNotRunningException
Ehcache.isNodeBulkLoadEnabled() returns true, this method will always return true.
Applies to caches clustered with Terracotta only.
isClusterBulkLoadEnabled in interface EhcacheUnsupportedOperationException - if the cache is not clustered with Terracotta
TerracottaNotRunningException
public boolean isNodeBulkLoadEnabled()
throws UnsupportedOperationException,
TerracottaNotRunningException
Ehcache.isClusterBulkLoadEnabled() method will always return true.
Applies to caches clustered with Terracotta only.
isNodeBulkLoadEnabled in interface EhcacheUnsupportedOperationException - if the cache is not clustered with Terracotta
TerracottaNotRunningException
public void setNodeBulkLoadEnabled(boolean enabledBulkLoad)
throws UnsupportedOperationException,
TerracottaNotRunningException
setBulkLoadEnabled(true) when the cache is already in bulk-load mode or
calling setBulkLoadEnabled(false) when already NOT in bulk-load mode will be a no-op.
Applies to caches clustered with Terracotta only.
When using Terracotta clustered caches with nonstop enabled, the timeout used by this method is
NonstopConfiguration.getBulkOpsTimeoutMultiplyFactor() times the timeout value in the nonstop config.
setNodeBulkLoadEnabled in interface EhcacheenabledBulkLoad - true enables bulk-load, false disables it if not already disabled
UnsupportedOperationException - if the cache is not clustered with Terracotta
TerracottaNotRunningException
public void waitUntilClusterBulkLoadComplete()
throws UnsupportedOperationException,
TerracottaNotRunningException
waitUntilClusterBulkLoadComplete in interface EhcacheUnsupportedOperationException - if the cache is not clustered with Terracotta
TerracottaNotRunningException
|
ehcache | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||