net.sf.ehcache
public class Cache extends Object implements Ehcache
Version: $Id: Cache.java 191 2006-09-03 22:41:48Z gregluck $
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. |
Constructor Summary | |
---|---|
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 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.
|
Object | clone()
Clones a cache. |
void | dispose()
Flushes all cache items from memory to auxilliary caches and close the auxilliary caches.
|
boolean | equals(Object object)
An equals method which follows the contract of Object#equals(Object)
|
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(Serializable key)
Gets an element from the cache. |
Element | get(Object key)
Gets an element from the cache. |
BootstrapCacheLoader | getBootstrapCacheLoader()
Accessor for the BootstrapCacheLoader associated with this cache. |
RegisteredEventListeners | getCacheEventNotificationService()
Use this to access the service in order to register and unregister listeners
|
CacheManager | getCacheManager()
Gets the CacheManager managing this cache. |
long | getDiskExpiryThreadIntervalSeconds() |
DiskStore | getDiskStore()
Gets the internal DiskStore.
|
int | getDiskStoreHitCount()
Number of times a requested item was found in the Disk Store. |
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.
|
int | getHitCount()
The number of times a requested item was found in the cache.
|
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. |
int | getMaxElementsInMemory()
Gets the maximum number of elements to hold in memory. |
MemoryStore | getMemoryStore()
Gets the internal MemoryStore.
|
MemoryStoreEvictionPolicy | getMemoryStoreEvictionPolicy()
The policy used to evict elements from the MemoryStore.
|
int | getMemoryStoreHitCount()
Number of times a requested item was found in the Memory Store.
|
long | getMemoryStoreSize()
Returns the number of elements in the memory store.
|
int | getMissCountExpired()
Number of times a requested element was found but was expired. |
int | getMissCountNotFound()
Number of times a requested element was not found in the cache. |
String | getName()
Gets the cache name. |
Element | getQuiet(Serializable key)
Gets an element from the cache, without updating Element statistics. |
Element | getQuiet(Object key)
Gets an element from the cache, without updating Element statistics. |
int | getSize()
Gets the size of the cache. |
Statistics | getStatistics()
{@inheritDoc }
Note, the Cache method will have the same value as the size reported by Statistics
for the statistics accuracy of STATISTICS_ACCURACY_BEST_EFFORT. |
int | getStatisticsAccuracy()
Accurately measuring statistics can be expensive. |
Status | getStatus()
Gets the status attribute of the Cache.
|
long | getTimeToIdleSeconds()
Gets timeToIdleSeconds. |
long | getTimeToLiveSeconds()
Gets timeToLiveSeconds. |
int | hashCode()
Returns a hash code value for the object. |
void | initialise()
Newly created caches do not have a MemoryStore or a DiskStore.
|
boolean | isDiskPersistent() |
boolean | isElementInMemory(Serializable key)
Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval.
|
boolean | isElementInMemory(Object key)
Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval.
|
boolean | isElementOnDisk(Serializable key)
Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval.
|
boolean | isElementOnDisk(Object key)
Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval.
|
boolean | isEternal()
Are elements eternal. |
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 | isOverflowToDisk()
Does the overflow go to disk. |
boolean | isValueInCache(Object value)
An extremely expensive check to see if the value exists in the cache. |
void | put(Element element)
Put an element in the cache.
|
void | put(Element element, boolean doNotNotifyCacheReplicators)
Put an element in the cache.
|
void | putQuiet(Element element)
Put an element in the cache, without updating statistics, or updating listeners. |
boolean | remove(Serializable key)
Removes an Element from the Cache. |
boolean | remove(Object key)
Removes an Element from the Cache. |
boolean | remove(Serializable key, boolean doNotNotifyCacheReplicators)
Removes an Element from the Cache. |
boolean | remove(Object 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(Serializable key)
Removes an Element from the Cache, without notifying listeners. |
boolean | removeQuiet(Object key)
Removes an Element from the Cache, without notifying listeners. |
void | setBootstrapCacheLoader(BootstrapCacheLoader bootstrapCacheLoader)
Sets the bootstrap cache loader.
|
void | setCacheManager(CacheManager cacheManager)
For use by CacheManager.
|
void | setDiskStorePath(String diskStorePath)
DiskStore paths can conflict between CacheManager instances. |
void | setName(String name)
Sets the cache name which will name.
|
void | setStatisticsAccuracy(int statisticsAccuracy)
Sets the statistics accuracy.
|
String | toString()
Returns a String representation of Cache. |
java -Dnet.sf.ehcache.disabled=true
in the command line.Parameters: name the name of the cache maxElementsInMemory the maximum number of elements in memory, before they are evicted overflowToDisk whether to use the disk store eternal whether the elements in the cache are eternal, i.e. never expire timeToLiveSeconds the default amount of time to live for an element from its creation date timeToIdleSeconds the default amount of time to live for an element from its last accessed or modified date
Since: 1.0
Parameters: name the name of the cache maxElementsInMemory the maximum number of elements in memory, before they are evicted overflowToDisk whether to use the disk store eternal whether the elements in the cache are eternal, i.e. never expire timeToLiveSeconds the default amount of time to live for an element from its creation date timeToIdleSeconds the default amount of time to live for an element from its last accessed or modified date diskPersistent whether to persist the cache to disk between JVM restarts diskExpiryThreadIntervalSeconds how often to run the disk store expiry thread. A large number of 120 seconds plus is recommended
Since: 1.1
Parameters: name the name of the cache maxElementsInMemory the maximum number of elements in memory, before they are evicted memoryStoreEvictionPolicy one of LRU, LFU and FIFO. Optionally null, in which case it will be set to LRU. overflowToDisk whether to use the disk store diskStorePath this parameter is ignored. CacheManager sets it using setter injection. eternal whether the elements in the cache are eternal, i.e. never expire timeToLiveSeconds the default amount of time to live for an element from its creation date timeToIdleSeconds the default amount of time to live for an element from its last accessed or modified date diskPersistent whether to persist the cache to disk between JVM restarts diskExpiryThreadIntervalSeconds how often to run the disk store expiry thread. A large number of 120 seconds plus is recommended registeredEventListeners a notification service. Optionally null, in which case a new one with no registered listeners will be created.
Since: 1.2
Parameters: name the name of the cache maxElementsInMemory the maximum number of elements in memory, before they are evicted memoryStoreEvictionPolicy one of LRU, LFU and FIFO. Optionally null, in which case it will be set to LRU. overflowToDisk whether to use the disk store diskStorePath this parameter is ignored. CacheManager sets it using setter injection. eternal whether the elements in the cache are eternal, i.e. never expire timeToLiveSeconds the default amount of time to live for an element from its creation date timeToIdleSeconds the default amount of time to live for an element from its last accessed or modified date diskPersistent whether to persist the cache to disk between JVM restarts diskExpiryThreadIntervalSeconds how often to run the disk store expiry thread. A large number of 120 seconds plus is recommended registeredEventListeners 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.
Since: 1.2.1
Returns: the approximate size of the memory store in bytes
Throws: IllegalStateException
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Returns: an object of type Cache
Throws: CloneNotSupportedException
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Parameters: object the reference object with which to compare.
Returns: true
if this object is the same as the obj
argument; false
otherwise. Same for a Cache means, the same GUID
See Also: hashCode java.util.Hashtable
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Parameters: key a serializable value
Returns: the element, or null, if it does not exist.
Throws: IllegalStateException if the cache is not STATUS_ALIVE
See Also: Cache
Parameters: key an Object value
Returns: the element, or null, if it does not exist.
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Since: 1.2
See Also: Cache
Returns: the RegisteredEventListeners instance for this cache.
Returns: the manager or null if there is none
Returns: the interval between runs of the expiry thread, where it checks the disk store for expired elements. It is not the the timeToLiveSeconds.
Returns: the DiskStore referenced by this cache
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Returns: the number of elements in the disk store.
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Returns: the globally unique identifier for this cache instance. This is guaranteed to be unique.
Since: 1.2
Returns: the number of times a requested item was found in the cache
Returns: a list of Object keys
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Returns: a list of Object keys
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Returns: a list of Object keys
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Returns: the MemoryStore referenced by this cache
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Since: 1.2
Returns: Number of times a requested item was found in the Memory Store.
Returns: the number of elements in the memory store
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Parameters: key a serializable value
Returns: the element, or null, if it does not exist.
Throws: IllegalStateException if the cache is not STATUS_ALIVE
See Also: Cache
Parameters: key a serializable value
Returns: the element, or null, if it does not exist.
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Since: 1.2
See Also: Cache
Returns: The size value
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Returns: one of STATISTICS_ACCURACY_BEST_EFFORT, STATISTICS_ACCURACY_GUARANTEED, STATISTICS_ACCURACY_NONE
Returns: The status value from the Status enum class
java.util.Hashtable
.
The general contract of hashCode
is:
hashCode
method on each of
the two objects must produce the same integer result.
Returns: a hash code value for this object.
See Also: Object#equals(Object) java.util.Hashtable
Returns: true if the cache overflows to disk and the disk is persistent between restarts
Returns: true if an element matching the key is found in memory
Returns: true if an element matching the key is found in memory
Since: 1.2
Returns: true if an element matching the key is found in the diskStore
Returns: true if an element matching the key is found in the diskStore
Since: 1.2
Returns: true if it has expired
Throws: IllegalStateException if the cache is not STATUS_ALIVE NullPointerException if the element is null
Parameters: key the key to check.
Returns: true if an Element matching the key is found in the cache. No assertions are made about the state of the Element.
Parameters: value to check for
Returns: true if an Element matching the key is found in the cache. No assertions are made about the state of the Element.
Parameters: element An object. If Serializable it can fully participate in replication and the DiskStore.
Throws: IllegalStateException if the cache is not STATUS_ALIVE IllegalArgumentException if the element is null
Parameters: element An object. If Serializable it can fully participate in replication and the DiskStore. doNotNotifyCacheReplicators whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a further notification to doNotNotifyCacheReplicators cache peers
Throws: IllegalStateException if the cache is not STATUS_ALIVE IllegalArgumentException if the element is null
Parameters: element An object. If Serializable it can fully participate in replication and the DiskStore.
Throws: IllegalStateException if the cache is not STATUS_ALIVE IllegalArgumentException if the element is null
Parameters: key the element key to operate on
Returns: true if the element was removed, false if it was not found in the cache
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Parameters: key the element key to operate on
Returns: true if the element was removed, false if it was not found in the cache
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Since: 1.2
Parameters: key the element key to operate on doNotNotifyCacheReplicators whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a further notification to doNotNotifyCacheReplicators cache peers
Returns: true if the element was removed, false if it was not found in the cache
Throws: IllegalStateException if the cache is not STATUS_ALIVE
UNKNOWN: SameParameterValue
Parameters: key the element key to operate on doNotNotifyCacheReplicators whether the put is coming from a doNotNotifyCacheReplicators cache peer, in which case this put should not initiate a further notification to doNotNotifyCacheReplicators cache peers
Returns: true if the element was removed, false if it was not found in the cache
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Parameters: key the element key to operate on
Returns: true if the element was removed, false if it was not found in the cache
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Parameters: key the element key to operate on
Returns: true if the element was removed, false if it was not found in the cache
Throws: IllegalStateException if the cache is not STATUS_ALIVE
Since: 1.2
Parameters: bootstrapCacheLoader the loader to be used
Throws: CacheException if this method is called after the cache is initialized
Parameters: cacheManager the CacheManager for this cache to use.
Parameters: diskStorePath the new path to be used.
Throws: CacheException if this method is called after the cache is initialized
Parameters: name the name of the cache. Should not be null. Should also not contain any '/' characters, as these interfere with distribution
Throws: IllegalArgumentException if an illegal name is used.
Parameters: statisticsAccuracy one of STATISTICS_ACCURACY_BEST_EFFORT, STATISTICS_ACCURACY_GUARANTEED, STATISTICS_ACCURACY_NONE