在项目中我们经常会用到数据缓存
也会在项目处理对缓存的维护
但是有些时间我们需要人为的来维护这些缓存
用下面的代码来实现
将缓存信息绑定到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();}}