+

Search Tips   |   Advanced Search

Invalidation listeners


Invalidation listener mechanism uses Java events for alerting applications when contents are removed from the cache.

Applications implement the InvalidationListener interface (defined in the com.ibm.websphere.cache package) and register it to the cache using the DistributedMap interface. Listeners receive InvalidationEvents (defined in the com.ibm.websphere.cache package) when entries from the cache are removed, due to an explicit user invalidation, timeout, least recently used (LRU) eviction, cache clear, or disk timeout.

Applications can immediately recalculate the invalidated data and prime the cache before the next user request.

Enable listener support in DistributedMap before registering listeners. DistributedMap can also be configured to use the invalidation listener Java EE context from registration time during callbacks.

Setting the value of the custom property useListenerContext to true enables the invalidation listener Java EE context for callbacks.

The following example shows how to set up an invalidation listener:

dmap.enableListener(true);  


// Enable cache invalidation listener. 
InvalidationListener listener = new MyListenerImpl();


//Create invalidation listener object. 
dmap.addInvalidationListener(listener);


//Add invalidation listener.
      :
      :
      : dmap.removeInvalidationListener(listener);

  
//Remove the invalidation listener. 


//This increases performance. dmap.enableListener(false);

// Disable cache invalidation listener.  

//This increases performance.





 

Related

Use the DistributedMap and DistributedObjectCache interfaces for the dynamic cache