Ehcache API Developer Guide : Cache Event Listeners : Registering Event Listeners during runtime
Registering Event Listeners during runtime
Cache event listeners may also be added and removed while the cache is being used.
ListenerObject listener = new ListenerObject();
cache.getRuntimeConfiguration().registerCacheEventListener(listener,
EventOrdering.ORDERED,
EventFiring.ASYNCHRONOUS, EnumSet.of(EventType.CREATED,
EventType.REMOVED));

cache.put(1L, "one");
cache.put(2L, "two");
cache.remove(1L);
cache.remove(2L);

cache.getRuntimeConfiguration().deregisterCacheEventListener(listener);

cache.put(1L, "one again");
cache.remove(1L);
1
Create a CacheEventListener implementation instance.
2
Register it on the RuntimeConfiguration, indicating the delivery mode and events of interest. The following put() and remove() cache calls will make the listener receive events.
3
Unregister the previously registered CacheEventListener instance. The following put() and remove() cache calls will have no effect on the listener anymore.
Copyright © 2010-2017 Software AG, Darmstadt, Germany. (Innovation Release)

Product LogoContact Support   |   Community   |   Feedback