Delegate CacheItemRemovedCallback
Defines a callback method for notifying applications when a cached item is removed from the Cache.
Namespace:
Assembly: Alachisoft.NCache.Web.dll
Syntax
[Obsolete("This delegate is deprecated. 'Please use CacheDataNotificationCallback(string key, CacheEventArg cacheEventArgs)'", false)]
public delegate void CacheItemRemovedCallback(string key, object value, CacheItemRemovedReason reason);
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The index location for the item removed from the cache. |
System.Object | value | The object item removed from the cache. |
CacheItemRemovedReason | reason | The reason the item was removed from the cache, as specified by the CacheItemRemovedReason enumeration. |
Remarks
Since this handler is invoked every time an item is removed from the Cache, doing a lot of processing inside the handler might have an impact on the performance of the cache and cluster. It is therefore advisable to do minimal processing inside the handler.
Examples
The following example demonstrates how to use the CacheItemRemovedCallback class to notify an application when an item is removed from the application's Cache object. You could include this code in a code declaration block in the Web Forms page, or in a page code-behind file.
static bool itemRemoved = false;
static CacheItemRemovedReason reason;
CacheItemRemovedCallback onRemove = null;
public void RemovedCallback(string k, object v, CacheItemRemovedReason r)
{
itemRemoved = true;
reason = r;
}
public void AddItemToCache(object sender, EventArgs e)
{
itemRemoved = false;
onRemove = new CacheItemRemovedCallback(this.RemovedCallback);
if (Cache["Key1"] == null)
NCache.Cache.Insert("Key1", "Value 1", null, DateTime.Now.AddMinutes(60), TimeSpan.Zero, CacheItemPriority.High, onRemove);
}