17 August, 2011

Programmatic Output Cache Entry Removal in Asp.net


Remove One Page from the Cache
This technique is simply to specify a particular page and have its output cache entry removed.
This is accomplished using the HttpResponse.RemoveOutputCacheItem(string path) method. The path expected is an “absolute virtual path” which means it must be of the form “/foldername/pagename.aspx”. From the sample code, you could create a button that, when pressed, removes the cache entry for a particular page.
 Remove Output Cache for One Page
private void RemoveButton_Click(object sender, System.EventArgs e)
{
    HttpResponse.RemoveOutputCacheItem("/caching/CacheForever.aspx");
}
 
This works provided that there is a page named CacheForever.aspx in the folder /caching.  On that page, you would implement output caching by using the <%@ OutputCache %> directive as usual -- nothing special needs to be done to the cached page for this technique to work.

No comments:

Post a Comment