Ehcache is the central interface. Caches have Elements and are managed
by the CacheManager. The Cache performs logical actions. It delegates physical
implementations to its net.s.
A reference to an EhCache can be obtained through the CacheManager. An Ehcache 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.
Statistics on cache usage are collected and made available through public methods.
| Modifier and Type | Method and Description |
|---|---|
| public void | acquireReadLockOnKey(Object
- The key that retrieves a value that you want to protect via locking key)Acquires the proper read lock for a given cache key |
| public void | acquireWriteLockOnKey(Object
- The key that retrieves a value that you want to protect via locking key)Acquires the proper write lock for a given cache key |
| public void | addPropertyChangeListener(PropertyChangeListener
the listener to add listener)Add a PropertyChangeListener. |
| public void | |
| public long | Returns: the approximate size of the memory store in bytes
Deprecated
Gets the size of the memory store for this cacheWarning This method can be very expensive to run. |
| public long | Returns: the size of the off-heap store in bytes
Deprecated
Gets the size of the off-heap store for this cache
|
| public long | Returns: the size of the on-disk store in bytes
Deprecated
Gets the size of the on-disk store for this cache
|
| public Object | |
| public Query | |
| public void | |
| public void | |
| public void | evictExpiredElements()
Causes all elements stored in the Cache to be synchronously checked for expiry, and if expired, evicted. |
| public void | |
| public Element | Returns: the element, or null, if it does not exist.a serializable value key)Gets an element from the cache. |
| public Element | |
| public Map | Returns: Map of key and elements for the provided keys, value will be null for the keys which do not exista collection of keys for which value is to be fetched keys)Gets all the elements from the cache for the keys provided. |
| public Map | Returns: a Map populated from the Cache. If there are no elements, an empty Map is returned.a collection of keys to be returned/loaded keys, Object an argument to pass to the CacheLoader. loaderArgument)The getAll method will return, from the cache, a Map of the objects associated with the Collection of keys in argument "keys". |
| public BootstrapCacheLoader | Returns: the BootstrapCacheLoader to useAccessor for the BootstrapCacheLoader associated with this cache. |
| public CacheConfiguration | Returns: CacheConfiguration the cache configurationGets the cache configuration this cache was created with. |
| public RegisteredEventListeners | Returns: the RegisteredEventListeners instance for this cache.Use this to access the service in order to register and unregister listeners |
| public CacheExceptionHandler | |
| public CacheManager | Returns: the manager or null if there is noneGets the CacheManager managing this cache. |
| public int | Returns: the number of elements in the disk store.
Deprecated
Returns the number of elements in the disk store.
|
| public String | Returns: the globally unique identifier for this cache instance. This is guaranteed to be unique.The GUID for this cache instance can be used to determine whether two cache instance references are pointing to the same cache. |
| public Object | |
| public List | |
| public List | Returns: a list ofObject keys
Deprecated
versions since 2.1 do not return duplicates
Returns a list of all elements in the cache, whether or not they are expired.
|
| public List | |
| public long | Returns: the number of elements in the memory store
Deprecated
Returns the number of elements in the memory store.
|
| public String | |
| public long | Returns: the number of elements in the off-heap store
Deprecated
Returns the number of elements in the off-heap store.
|
| public Element | Returns: the element, or null, if it does not exist.a serializable value key)Gets an element from the cache, without updating Element statistics. |
| public Element | |
| public List | |
| public List | |
| public CacheWriter | Returns: the registeredCacheWriter; or null if none was registered beforeRetrieves the |
| public < type of the attribute T> Attribute | Returns: the search attributethe name of the attribute to retrieve attributeName)Retrieve the given named search attribute |
| public Set | Returns: set of all search attributes in effect at the time of calling this method
|
| public int | |
| public StatisticsGateway | Returns: the statistics gatewayGets an immutable Statistics object representing the Cache statistics at the time. |
| public Status | Returns: The status value from the Status enum classGets the status attribute of the Cache. |
| public Element | Returns: an element if it existed or could be loaded, otherwise nullkey whose associated value is to be returned. key, CacheLoader the override loader to use. If null, the cache's default loader will be used loader, Object an argument to pass to the CacheLoader. loaderArgument)This method will return, from the cache, the object associated with the argument "key". |
| public CacheWriterManager | Returns: the writer manager that's set up for this cacheObtain the writer manager that's used by this cache instance. |
| public boolean | Returns: true if the cache may contain partially sized objectsCheck if the cache may contain elements which the SizeOf engine could not fully size. |
| public void | initialise()
Newly created caches do not have a |
| public boolean | Returns: true if the cache is in bulk-load mode cluster-wide, false otherwiseReturns true if at least one node in the cluster is in bulk-load mode. |
| public boolean | Returns: true if the cache is in coherent mode cluster-wide, false otherwise
Deprecated
Use
Returns true if the cache is in coherent mode cluster-wide.
isClusterBulkLoadEnabled() instead
|
| public boolean | |
| public boolean | Returns: true if an element matching the key is found in memorythe key of the element to remove key)Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval. |
| public boolean | Returns: true if an element matching the key is found in memorythe key of the element to remove key)Whether an Element is stored in the cache in Memory, indicating a very low cost of retrieval. |
| public boolean | Returns: true if an element matching the key is found in the diskStorethe key of the element to remove key)Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval. |
| public boolean | Returns: true if an element matching the key is found in the diskStorethe key of the element to remove key)Whether an Element is stored in the cache on Disk, indicating a higher cost of retrieval. |
| public boolean | |
| public boolean | Returns: true if an Element matching the key is found in the cache. No assertions are made about the state of the Element.the key to check for key)An inexpensive check to see if the key exists in the cache. |
| public boolean | Returns: true if the cache is in coherent mode cluster-wide, false otherwiseReturns true if the current node is in bulk-load mode. |
| public boolean | Returns: true if the cache is in coherent mode cluster-wide, false otherwise
Deprecated
Use
Returns true if the cache is in coherent mode for the current node.
isNodeBulkLoadEnabled() instead
|
| public boolean | Returns: true if a read lock for the key is held by the current threadthe key key)Returns true if a read lock for the key is held by the current thread |
| public boolean | |
| public boolean | Returns: true if an Element matching the key is found in the cache. No assertions are made about the state of the Element.to check for value)An extremely expensive check to see if the value exists in the cache. |
| public boolean | Returns: true if a write lock for the key is held by the current threadthe key key)Returns true if a write lock for the key is held by the current thread |
| public void | |
| public void | loadAll(final Collection<E>
- collection of the keys whose associated values to be loaded into this cache by using the associated
cacheloader if this cache doesn't contain them. keys, final Object can be anything that makes sense to the loader
argument)
The Ehcache native API provides similar functionality to loaders using the
decorator The loadAll method provides a means to "pre load" objects into the cache. |
| public void | |
| public void | put(Element
An object. If Serializable it can fully participate in replication and the DiskStore. element, boolean 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 doNotNotifyCacheReplicators)Put an element in the cache. |
| public void | putAll(Collection<Element>
the collection of elements to be put in the cache. elements)Puts a collection of elements in to the cache. |
| public Element | Returns: the element previously cached for this key, or null if none.element to be added element)Put an element in the cache if no element is currently mapped to the elements key. |
| public Element | Returns: the element previously cached for this key, or null if none.element to be added element, boolean 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 doNotNotifyCacheReplicators)Put an element in the cache if no element is currently mapped to the elements key. |
| public void | |
| public void | putWithWriter(Element
An object. If Serializable it can fully participate in replication and the DiskStore. element)Put an element in the cache writing through a CacheWriter. |
| public void | registerCacheExtension(CacheExtension
the cache extension cacheExtension)Register a |
| public void | registerCacheLoader(CacheLoader
A Cache Loader to register cacheLoader)Register a |
| public void | registerCacheWriter(CacheWriter
A CacheWriter to register cacheWriter)Register the |
| public void | registerDynamicAttributesExtractor(DynamicAttributesExtractor
the dynamic attribute extractor extractor)Allows user to register a dynamic attribute extractor with a searchable cache that is dynamically indexable, as indicated by its configuration. |
| public void | releaseReadLockOnKey(Object
- The key that retrieves a value that you want to protect via locking key)Release a held read lock for the passed in key |
| public void | releaseWriteLockOnKey(Object
- The key that retrieves a value that you want to protect via locking key)Release a held write lock for the passed in key |
| public boolean | Returns: true if the element was removed, false if it was not found in the cachethe key of the element to remove key)Removes an |
| public boolean | Returns: true if the element was removed, false if it was not found in the cachethe key of the element to remove key)Removes an |
| public boolean | Returns: true if the element was removed, false if it was not found in the cachethe key of the element to remove key, boolean 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 doNotNotifyCacheReplicators)Removes an |
| public boolean | Returns: true if the element was removed, false if it was not found in the cacheof the element to remove key, boolean 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 doNotNotifyCacheReplicators)Removes an |
| public void | removeAll(Collection<?>
a collection of keys to operate on keys)Removes given set of |
| public void | removeAll(Collection<?>
a collection of keys to operate on keys, boolean 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 doNotNotifyCacheReplicators)Removes all cached items. |
| public void | |
| public void | removeAll(boolean
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 doNotNotifyCacheReplicators)Removes all cached items. |
| public boolean | Returns: true if the value was removedElement to be removed element)Remove the Element mapped to the key for the supplied element if the value of the supplied Element compares equal to the value of the cached Element. |
| public void | removePropertyChangeListener(PropertyChangeListener
the listener to remove listener)Remove a PropertyChangeListener. |
| public boolean | Returns: true if the element was removed, false if it was not found in the cacheof the element to remove key)Removes an |
| public boolean | Returns: true if the element was removed, false if it was not found in the cacheof the element to remove key)Removes an |
| public boolean | Returns: true if the element was removed, false if it was not found in the cacheof the element to remove key)Removes an |
| public boolean | |
| public Element | |
| public void | setBootstrapCacheLoader(BootstrapCacheLoader
the loader to be used bootstrapCacheLoader)Sets the bootstrap cache loader. |
| public void | setCacheExceptionHandler(CacheExceptionHandler
the cache exception handler cacheExceptionHandler)Sets an ExceptionHandler on the Cache. |
| public void | setCacheManager(CacheManager
the CacheManager for this cache to use. cacheManager)Sets the CacheManager |
| public void | setDisabled(boolean
true if you wish to disable, false to enable disabled)Disables or enables this cache. |
| public void | |
| public void | setNodeBulkLoadEnabled(boolean
true enables bulk-load, false disables it if not already disabled enabledBulkLoad)Enable/disable bulk-load mode in this node for this cache. |
| public void | setNodeCoherent(boolean
true transitions to coherent mode, false to incoherent mode coherent)
Deprecated
Use
Sets the cache in coherent or incoherent mode depending on the parameter on this node.
setNodeBulkLoadEnabled(boolean) instead
|
| public void | setTransactionManagerLookup(TransactionManagerLookup
the transactionManagerLookup transactionManagerLookup)This class is used to access the transaction manager used during XA. |
| public String | |
| public boolean | Returns: whether the lock was awarded- The key that retrieves a value that you want to protect via locking key, long - millis until giveup on getting the lock timeout)Try to get a read lock on a given key. |
| public boolean | Returns: whether the lock was awarded- The key that retrieves a value that you want to protect via locking key, long - millis until giveup on getting the lock timeout)Try to get a write lock on a given key. |
| public void | unregisterCacheExtension(CacheExtension
the cache extension cacheExtension)Unregister a |
| public void | unregisterCacheLoader(CacheLoader
A Cache Loader to unregister cacheLoader)Unregister a |
| public void | |
| public void | waitUntilClusterBulkLoadComplete()
This method waits until all the connected nodes have disabled bulk-load. |
| public void | waitUntilClusterCoherent()
Deprecated
Use
This method waits until the cache is in coherent mode in all the connected nodes.
waitUntilClusterBulkLoadComplete() instead
|