The .NET Framework (2.0 in this case) contains a class exposing operations into the server Cache. It's namespace/path is System.Web.Caching.Cache, and clearing it is the easy part.
// declare a placeholder for your Cache data.
private System.Web.Caching.Cache TheCache;
// assign your placeholder to the value of your current webserver cache.
TheCache = HttpContext.Current.Cache;
And in your button click event handler:
protected void btnClearCache_Click(object sender, EventArgs e)
{
// clear the cache
foreach (DictionaryEntry key in TheCache)
{
string theKey = key.Key.ToString();
TheCache.Remove(theKey);
}
}
Pretty simple, right? How about we make this a usercontrol, and provide the use with a list of current items in the Cache, as well as an option to remove only those he/she wants to remove as well as a clear all button?
Here is the code for my UserControl page (ucCacheKiller.ascx)
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucCacheKiller.ascx.cs"
Inherits="WilsToolbox.ucCacheKiller" %>
<table>
<tr>
<td align="left" colspan="2">
<asp:Label ID="lblCacheHeader" runat="server" Font-Bold="True" Font-Names="Tahoma"
&am