消除aspx頁面緩存的法式完成辦法。本站提示廣大學習愛好者:(消除aspx頁面緩存的法式完成辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是消除aspx頁面緩存的法式完成辦法正文
本文實例引見了消除aspx頁面緩存的法式完成辦法,詳細步調以下:
一切用到頁面緩存的aspx頁面修正以下cs,讓它繼續一個自界說基類(例如:PageCacheBase);
PageCacheBase 的 Page_Load
參加以下代碼:
string cacheKey = Request.Url.ToString(); Cache[cacheKey] = new object(); Response.AddCacheItemDependency(cacheKey);
如許就可以在運用法式(全部網站)Cache裡遍歷緩存項(包含這些aspx頁面的緩存依附項)了,我把他們綁定到DataGrid:
private void bindCache()
{
DataTable dt = new DataTable();
dt.Columns.Add("CacheName",typeof(string));
dt.Columns.Add("CacheType",typeof(string));
IDictionaryEnumerator CacheEnum =
HttpRuntime.Cache.GetEnumerator();
while (CacheEnum.MoveNext())
{
DataRow dr = dt.NewRow();
dr["CacheName"] = CacheEnum.Key;
dr["CacheType"] = CacheEnum.Value.GetType();
dt.Rows.Add(dr);
}
DataView dv = dt.DefaultView;
dv.Sort = "CacheName";
this.DataGrid1.DataSource =dt;
this.DataGrid1.DataBind();
}
刪除就簡略了,完成代碼以下:
string cacheKey = e.Item.Cells[0].Text;
if(Cache[cacheKey]!=null)
{
Cache.Remove(cacheKey);
bindCache();
}