Interface CacheEventListener
-
- All Superinterfaces:
java.lang.Cloneable
- All Known Subinterfaces:
CacheReplicator
- All Known Implementing Classes:
CacheEventListenerAdapter,RMIAsynchronousCacheReplicator,RMISynchronousCacheReplicator,TerracottaCacheEventReplication
public interface CacheEventListener extends java.lang.CloneableAllows implementers to register callback methods that will be executed when a cache event occurs. The events include:- put Element
- update Element
- remove Element
- evict Element
- an Element expires, either because timeToLive or timeToIdle has been reached.
- removeAll, which causes all elements to be cleared from the cache
Callbacks to these methods are synchronous and unsynchronized. It is the responsibility of the implementer to safely handle the potential performance and thread safety issues depending on what their listener is doing.
Cache also has putQuiet and removeQuiet methods which do not notify listeners.
- Since:
- 1.2
- Version:
- $Id$
- Author:
- Greg Luck
- See Also:
CacheManagerEventListener
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Objectclone()Creates a clone of this listener.voiddispose()Give the listener a chance to cleanup and free resources when no longer neededvoidnotifyElementEvicted(Ehcache cache, Element element)Called immediately after an element is evicted from the cache.voidnotifyElementExpired(Ehcache cache, Element element)Called immediately after an element is found to be expired.voidnotifyElementPut(Ehcache cache, Element element)Called immediately after an element has been put into the cache.voidnotifyElementRemoved(Ehcache cache, Element element)Called immediately after an attempt to remove an element.voidnotifyElementUpdated(Ehcache cache, Element element)Called immediately after an element has been put into the cache and the element already existed in the cache.voidnotifyRemoveAll(Ehcache cache)Called duringEhcache.removeAll()to indicate that the all elements have been removed from the cache in a bulk operation.
-
-
-
Method Detail
-
notifyElementRemoved
void notifyElementRemoved(Ehcache cache, Element element) throws CacheException
Called immediately after an attempt to remove an element. The remove method will block until this method returns.This notification is received regardless of whether the cache had an element matching the removal key or not. If an element was removed, the element is passed to this method, otherwise a synthetic element, with only the key set is passed in.
This notification is not called for the following special cases:
- removeAll was called. See
notifyRemoveAll(net.sf.ehcache.Ehcache) - An element was evicted from the cache.
See
notifyElementEvicted(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)
- Parameters:
cache- the cache emitting the notificationelement- the element just deleted, or a synthetic element with just the key set if no element was removed.- Throws:
CacheException
- removeAll was called. See
-
notifyElementPut
void notifyElementPut(Ehcache cache, Element element) throws CacheException
Called immediately after an element has been put into the cache. TheCache.put(net.sf.ehcache.Element)method will block until this method returns.Implementers may wish to have access to the Element's fields, including value, so the element is provided. Implementers should be careful not to modify the element. The effect of any modifications is undefined.
- Parameters:
cache- the cache emitting the notificationelement- the element which was just put into the cache.- Throws:
CacheException
-
notifyElementUpdated
void notifyElementUpdated(Ehcache cache, Element element) throws CacheException
Called immediately after an element has been put into the cache and the element already existed in the cache. This is thus an update.The
Cache.put(net.sf.ehcache.Element)method will block until this method returns.Implementers may wish to have access to the Element's fields, including value, so the element is provided. Implementers should be careful not to modify the element. The effect of any modifications is undefined.
- Parameters:
cache- the cache emitting the notificationelement- the element which was just put into the cache.- Throws:
CacheException
-
notifyElementExpired
void notifyElementExpired(Ehcache cache, Element element)
Called immediately after an element is found to be expired. TheCache.remove(Object)method will block until this method returns.Elements are checked for expiry in ehcache at the following times:
- When a get request is made
- When an element is spooled to the diskStore in accordance with a MemoryStore eviction policy
- In the DiskStore when the expiry thread runs, which by default is
Cache.DEFAULT_EXPIRY_THREAD_INTERVAL_SECONDS
- Parameters:
cache- the cache emitting the notificationelement- the element that has just expiredDeadlock Warning: expiry will often come from the
DiskStoreexpiry thread. It holds a lock to the DiskStorea the time the notification is sent. If the implementation of this method calls into a synchronizedCachemethod and that subsequently calls into DiskStore a deadlock will result. Accordingly implementers of this method should not call back into Cache.
-
notifyElementEvicted
void notifyElementEvicted(Ehcache cache, Element element)
Called immediately after an element is evicted from the cache. Evicted in this sense means evicted from one store and not moved to another, so that it exists nowhere in the local cache.In a sense the Element has been removed from the cache, but it is different, thus the separate notification.
- Parameters:
cache- the cache emitting the notificationelement- the element that has just been evicted
-
notifyRemoveAll
void notifyRemoveAll(Ehcache cache)
Called duringEhcache.removeAll()to indicate that the all elements have been removed from the cache in a bulk operation. The usualnotifyElementRemoved(net.sf.ehcache.Ehcache, net.sf.ehcache.Element)is not called.This notification exists because clearing a cache is a special case. It is often not practical to serially process notifications where potentially millions of elements have been bulk deleted.
- Parameters:
cache- the cache emitting the notification
-
clone
java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionCreates a clone of this listener. This method will only be called by ehcache before a cache is initialized.This may not be possible for listeners after they have been initialized. Implementations should throw CloneNotSupportedException if they do not support clone.
- Returns:
- a clone
- Throws:
java.lang.CloneNotSupportedException- if the listener could not be cloned.
-
dispose
void dispose()
Give the listener a chance to cleanup and free resources when no longer needed
-
-