Alachisoft NCache 4.1 - Online Documentation

Getting notified when an item is removed

 
Create a class with a name (could be any name) 'CacheEventListner' which implements ' CacheItemUpdatedCallback' from com.alachisoft.ncache.caching.
 
import com.alachisoft.ncache.web.caching.*;
 
public class CacheEventListner implements CacheItemRemovedCallback
{
public void itemRemoved(String string)
{
System.out.println("Cache Key" + string + " is Removed");
}
}
 
Subscriber of the event needs to register itself to get notifications. Now simply add an item to get the Notification:
 
CacheEventListner onItemRemoved = new CacheEventListner();
Cache _cache = NCache.initializeCache("myCache");
CacheItem cItem = new CacheItem("my Item");
cItem.setItemRemoveCallback(onItemRemoved);
_cache.insert("x-y-z", "my Item");
 
 
 
See Also
 
Copyright © 2005-2012 Alachisoft. All rights reserved.