1. 程式人生 > >Asp.net(C#)-顯示所有快取 清除所有快取

Asp.net(C#)-顯示所有快取 清除所有快取

//清除所有快取
protected void RemoveAllCache()
{
System.Web.Caching.Cache _cache = HttpRuntime.Cache;
IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
ArrayList al = new ArrayList();
while (CacheEnum.MoveNext())
{
al.Add(CacheEnum.Key);
}
foreach (string key in al)
{
_cache.Remove(key);
}
show();
}
//顯示所有快取
void show()
{
string str = "";
IDictionaryEnumerator CacheEnum = HttpRuntime.Cache.GetEnumerator();

while (CacheEnum.MoveNext())
{
str += "快取名<b>[" + CacheEnum.Key+"]</b><br />" ;
}
this.Label1.Text = "當前網站總快取數:" + HttpRuntime.Cache.Count + "<br />"+str;
}