Alachisoft NCache 4.1 - Online Documentation

General Purpose Events

NCache notifies client applications whenever an add, insert, remove or clear operation is done against the cache. These are cluster-wide notifications, and Java applications can receive them.
Cache Item Added Notification
  1. Create a class with a name (can be any name) 'CacheEventListner' which implements 'CacheListener' from com.alachisoft.ncache.event.
    import com.alachisoft.ncache.web.caching.*;
    import com.alachisoft.ncache.event.*;
    public class CacheEventListner implements CacheListener
    public void cacheCleared()
    System.out.println("Cache Cleared");
    public void cacheItemAdded(CacheEvent ce)
    System.out.println("Cache Item Added");
    public void cacheItemRemoved(CacheEvent ce)
    System.out.println("Cache Item Removed");
    public void cacheItemUpdated(CacheEvent ce)
    System.out.println("Cache Item Updated");
  2. Subscriber of the event needs to register itself to get the notifications. Now simply add an item to get the Notification.
    CacheEventListner cacheListner = new CacheEventListner();
    Cache _cache = NCache.initializeCache("myCache");
    _cache.add("Customer:David:1001", "my Item");
See Also
Copyright © 2005-2012 Alachisoft. All rights reserved.