清除aspx頁面緩存的程序?qū)崿F(xiàn)方法
本文實例介紹了清除aspx頁面緩存的程序?qū)崿F(xiàn)方法,具體步驟如下:
所有用到頁面緩存的aspx頁面修改以下cs,讓它繼承一個自定義基類(例如:PageCacheBase);
PageCacheBase 的 Page_Load
加入以下代碼:
string cacheKey = Request.Url.ToString(); Cache[cacheKey] = new object(); Response.AddCacheItemDependency(cacheKey);
這樣就能在應(yīng)用程序(整個網(wǎng)站)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();
}
刪除就簡單了,實現(xiàn)代碼如下:
string cacheKey = e.Item.Cells[0].Text;
if(Cache[cacheKey]!=null)
{
Cache.Remove(cacheKey);
bindCache();
}
相關(guān)文章
c# 連接access數(shù)據(jù)庫config配置
c# 連接access數(shù)據(jù)庫config配置,需要的朋友可以參考一下2013-02-02
聊聊C# 中HashTable與Dictionary的區(qū)別說明
這篇文章主要介紹了聊聊C# 中HashTable與Dictionary的區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-01-01
C#刪除只讀文件或文件夾(解決File.Delete無法刪除文件)
這篇文章主要介紹了C#刪除只讀文件或文件夾(解決File.Delete無法刪除文件),需要的朋友可以參考下2015-09-09
Visual Studio連接unity編輯器的實現(xiàn)步驟
unity編輯器中打開C#腳本的時候發(fā)現(xiàn)Visual Studio沒有連接unity編輯器,本文主要介紹了Visual Studio連接unity編輯器的實現(xiàn)步驟,感興趣的可以了解一下2023-11-11
C#優(yōu)雅的實現(xiàn)INotifyPropertyChanged接口
這篇文章介紹了C#實現(xiàn)INotifyPropertyChanged接口的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08

