Is it possible to notify application when item is removed from cache ?

 Posted by Bhakti on 11/16/2009 | Category: C# Interview questions | Views: 4132

You can use CacheItemRemovedCallback delegate defining signature for event handler to call when item is removed from cache.

For an example:

"CacheItem1", //insert cache item
new TimeSpan(0, 0, 15),
new CacheItemRemovedCallback(RemovalMethod)); //define method which needs to be called when item is removed from cache

the method will be like,

private static string RemovedAt = string.Empty;
public static void RemovalMethod(String key, object value, //method is declared static so that it can be available when cache item is deleted
CacheItemRemovedReason removedReason)
RemovedAt = "Cache Item Removed at: " + DateTime.Now.ToString(); //Shows the time when cache item was removed

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response