NCache 4.3 - Online Documentation

General Purpose Events

 
NOTE: This feature is not available in NCache Express and Professional edition.
 
NCache notifies client applications whenever an add, insert, remove or clear operation is done against the cache. These are cluster-wide notifications and both .NET and Java applications can receive them.
 
Note: Before using general purpose notifications you have to enable them from NCache Manager. See How to Enable.
 
 
Add the following namespaces in your application for using events:
 
using Alachisoft.NCache.Web.Caching;
using Alachisoft.NCache.Runtime;
 
Cache Item Removed Notification
 
  1. Write event-handler procedure having event-handling code. For example, the following code shows the key which is being removed from the cache, in a message box.
     
    public void onCacheItemRemoved (string key, object o, CacheItemRemovedReason r)
    {
    MessageBox.Show(key + "is Removed from the cache");
    }
     
  2. Subscriber of the event needs to register itself to get notifications. Secondly, it has to specify event handler that must be called by CacheItemRemovedCallback delegate.
     
    _cache.ItemRemoved += new CacheItemRemovedCallback(this.onCacheItemRemoved);
     
    When an item is removed from the cache, the onCacheItemRemoved method is called.
 
Cache Item Added Notification
 
  1. Create event handler to respond when an item is added to the cache. For example, the following code shows the key information that is being added to the cache, in a message box.
     
    public void onCacheItemAdded (string key)
    {
    MessageBox.Show(key + "is Added to the cache ");
    }
     
  2. Subscriber of the event needs to register itself to get the notification. Secondly, it has to specify the event handler that must be called by CacheItemAddedCallback delegate.
     
    _cache.ItemAdded += new CacheItemAddedCallback(this.onCacheItemAdded);
     
    When an item is added to the cache, the onCacheItemAdded method is called.
 
Cache Item Updated Notification
 
  1. Create event handler to respond when an item is inserted to the cache. For example, the following code shows key information that is being inserted to the cache, in a message box.
     
    public void onCacheItemUpdated(string key)
    {
    MessageBox.Show(key + "is Inserted to the cache");
    }
     
  2. Subscriber of the event needs to register itself to get the notification. Secondly, it has to specify event handler that must be called by CacheItemUpdatedCallback delegate.
     
    _cache.ItemUpdated += new CacheItemUpdatedCallback(this.onCacheItemUpdated);
     
    When an item is removed from the cache, the onCacheItemUpdated method is called.
 
Cache Cleared Notification
 
  1. Create event handler to respond when cache is cleared. For example, the following code informs client application that cache has cleared, through a message box.
     
    public void onCacheCleared()
    {
    MessageBox.Show("cache is cleared");
    }
     
  2. Subscriber of the event needs to register itself to get notification. Secondly, it has to specify event handler that must be called by CacheClearedCallback delegate.
     
    _cache.CacheCleared += new CacheClearedCallback(this.onCacheCleared);
     
    When an item is removed from the cache, the onCacheCleared method is called.
 
 
 
See Also
 
© Copyright  2014 Alachisoft. All rights reserved.