Does anyone know a tutorial or an example on how can i run a function in asp.net, when a cache expires? I have read about a callback which is made when a cache expires, but i didn't find any examples. I need this for a website. It needs to execute a function on an exact hour every day.
Asked
Active
Viewed 7,351 times
2 Answers
3
hhh3112,
You can use a callback when the cache expires. can you explain a little more. I am not sure what you mean by the process has to execute on an exact hour of everyday.
string test = "test1";
Cache.Insert("Key", test, dependancy, DateTime.Now.AddMinutes(DateTime.Now), System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.High, new CacheItemRemovedCallback(CacheRemovedCallback));
public string CacheRemovedCallback(String key, object value, System.Web.Caching.CacheItemRemovedReason removedReason)
{
//Do something here
return = "Cache Expired for : " + key;
}

H20rider
- 2,162
- 5
- 29
- 47
-
Using Cache.Insert, can i set the respective cache to expire at an exact date, and when it does expire to execute the CacheRemovedCallback? – hhh3112 May 24 '11 at 20:41
1
See CacheItemRemovedCallback in the following ASP.NET Caching: Techniques and Best Practices.

Prisoner ZERO
- 13,848
- 21
- 92
- 137