How to programatically clear ASP.NET cache

asp.netcaching

In ASP.NET Webforms, I can use <%@ OutputCache Duration="3600" VaryByParam="none"%> to cache a web page. I have very static data that will be infrequently updated, but when it is updated the HTML on the web page will change. This data will be tied to a management system allowing maintainers to make appropriate edits.

I'd like to have a way to set the duration of the OutputCache to be very long. But I would also like to be able to clear this web page from the cache when the data is updated (preferably from the data editing page).

What is the standard way of accomplishing this in ASP.NET?

Best Answer

For Each de As DictionaryEntry In HttpContext.Current.Cache
   HttpContext.Current.Cache.Remove(DirectCast(de.Key, String))
Next

MSDN Cache.Remove

Edit: Here are further informations on how to remove a page from the OutputCache: