Search code examples
asp.netvb.netcachingoutputcache

Force update cache when using OutputCache


I am using ASP.NET Web Forms app with OutputCache set to xxx seconds. How can I invalidate cache when it is required to do? Specifically, I want to check if data in database is modified and if true, then force cache update. Is it possible and how to achieve that? So far I have added:

<%@ OutputCache Duration="24000" VaryByParam="myId" location="Server"%>

Now the problem is that Page_init is not fired with OutputCache and I dont know how to force cache update.

Any ideas are welcome!

Thanks!


Solution

  • Try this

    var urlToRemove = Url.Action("AjaxHtmlOutputMethod", "Controller");
    HttpResponse.RemoveOutputCacheItem(urlToRemove);