在項目中我們經常會用到數據緩存
也會在項目處理對緩存的維護
但是有些時間我們需要人為的來維護這些緩存
用下面的代碼來實現
將緩存信息綁定到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