熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

在asp.net 中實現維護數據緩存

2013-11-13 10:28:53  來源: .NET編程 
在項目中我們經常會用到數據緩存也會在項目處理對緩存的維護但是有些時間我們需要人為的來維護這些緩存用下面的代碼來實現
 
  將緩存信息綁定到DataGrid上
 

  private void bindCache() { string str = thisTextBoxTextTrim(); DataTable table = new DataTable(); tableColumnsAdd(CacheName typeof(string)); tableColumnsAdd(CacheType typeof(string)); IDictionaryEnumerator enumerator = HttpRuntimeCacheGetEnumerator(); int num = ; while (enumeratorMoveNext()) { bool flag = true; if ((str != ) && (enumeratorKeyToString()IndexOf(str) < )) { flag = false; } if (flag) { num++; DataRow row = tableNewRow(); row[CacheName] = enumeratorKey; row[CacheType] = enumeratorValueGetType(); tableRowsAdd(row); } } thisLabelText = numToString()Trim(); thisDataGridDataSource = table; thisDataGridDataBind(); }

 
  清除指定的緩存

   private void DataGrid_DeleteCommand(object source SystemWebUIWebControlsDataGridCommandEventArgs e) { string text = eItemCells[]Text; if (baseCache[text] != null) { baseCacheRemove(text); thisbindCache(); } }


 
From:http://tw.wingwit.com/Article/program/net/201311/13781.html
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.