I have enabled page caching for my ASPX pages with
<%@ OutputCache Duration="7200" VaryByParam="*" Location="Server" %>
However, the next time the page is regenerated, if there happens to be an error in the page, that also gets cached, and the site continues to display the page with errors in it for the next 7200 seconds or until some dependancy flushes the cache.
Currently I tried adding the sites error log as a file dependancy, so that anytime an error is logged, pages are refreshed. However, that causes the pages to be refreshed, even when another page in the site has an error.
Question is, How can I put a piece of code in the error handling block to uncache the current page..
Pseudo code.
try
{
page load
}
catch (Exception ex)
{
// Add C# code to not cache the current page this time.
}
You can simply use
HttpResponse.RemoveOutputCacheItem
as follows:See: Any way to clear/flush/remove OutputCache?
Another way to do that catch exception in
Application_Error
and useResponse.Cache.AddValidationCallback
, from this solution: