How to use Removecallback when cache item is removed from appliaction

To receive notification when a cached item is removed from the cache.we have CacheItemRemovedCallback.


public static void LoadCache(String pKey, Object obj)
{
HttpContext.Current.Cache.Insert(pKey, obj, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration, CacheItemPriority.Normal, new CacheItemRemovedCallback(RemovedCallback));

}


public static void RemovedCallback(String k, Object v, CacheItemRemovedReason r)
{
HttpContext.Current.Response.Write("Key:"+k+"
");
HttpContext.Current.Response.Write("Object:"+v.ToString()+"
")
HttpContext.Current.Response.Write("Reason:"+r)

}


Comments

Author: chaithanya11 Jun 2008 Member Level: Silver   Points : 1

Nice Post,its really useful for me in learning about Caching.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: