Answer: Yes.
You can use
CacheItemRemovedCallback delegate defining signature for event handler to call when item is removed from cache.
For an example:
HttpRuntime.Cache.Insert(
"CacheItem1", //insert cache item
"",
null,
Cache.NoAbsoluteExpiration,
new TimeSpan(0, 0, 15),
CacheItemPriority.Default,
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