Defines a callback method for notifying applications when a cached item is removed from the Cache.

Namespace: Alachisoft.NCache.Web.Caching
Assembly: Alachisoft.NCache.Web (in Alachisoft.NCache.Web.dll) Version: 4.1.0.0 (4.1.0.0)

Syntax

C#
public delegate void CacheItemRemovedCallback(
	string key,
	Object value,
	CacheItemRemovedReason reason
)
Visual Basic
Public Delegate Sub CacheItemRemovedCallback ( _
	key As String, _
	value As Object, _
	reason As CacheItemRemovedReason _
)
Visual C++
public delegate void CacheItemRemovedCallback(
	String^ key, 
	Object^ value, 
	CacheItemRemovedReason reason
)

Parameters

key
Type: System..::..String
The index location for the item removed from the cache.
value
Type: System..::..Object
The object item removed from the cache.
reason
Type: Alachisoft.NCache.Web.Caching..::..CacheItemRemovedReason
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 notifiy 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.
CopyC#
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);
   }

See Also