Terracotta Ehcache 10.5 | 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(); // 1
cache.getRuntimeConfiguration().registerCacheEventListener(listener,
EventOrdering.ORDERED,
EventFiring.ASYNCHRONOUS, EnumSet.of(EventType.CREATED,
EventType.REMOVED)); // 2

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

cache.getRuntimeConfiguration().deregisterCacheEventListener(listener); // 3

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-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.