首页  ·  知识 ·  编程语言
asp.net中实现维护数据缓存
IT实验室  http://dotnet.chinaitlab.com/CSharp/739639.html  VB  编辑:dezai  图片来源:网络
在项目中我们经常会用到数据缓存,也会在项目处理对缓存的维护,但是有些时间我们需要人为的来维护这些缓存,用下面的代码来实现:   1、将缓存

在项目中我们经常会用到数据缓存,也会在项目处理对缓存的维护,但是有些时间我们需要人为的来维护这些缓存,用下面的代码来实现:
 
  1、将缓存信息绑定到DataGrid上
 
private void bindCache()
{
string str = this.TextBox1.Text.Trim();
DataTable table = new DataTable();
table.Columns.Add("CacheName", typeof(string));
table.Columns.Add("CacheType", typeof(string));
IDictionaryEnumerator enumerator = HttpRuntime.Cache.GetEnumerator();
int num = 0; while (enumerator.MoveNext())
{
bool flag = true; if ((str != "") && (enumerator.Key.ToString().IndexOf(str) < 0))
{
flag = false;
}
if (flag)
{
num++; DataRow row = table.NewRow(); row["CacheName"] = enumerator.Key; row["CacheType"] = enumerator.Value.GetType();
table.Rows.Add(row);
}
}
this.Label1.Text = num.ToString().Trim();
this.DataGrid1.DataSource = table; this.DataGrid1.DataBind();
}

 
  2、清除指定的缓存

 private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
 {
 string text = e.Item.Cells[0].Text;
 if (base.Cache[text] != null)
 {
 base.Cache.Remove(text); this.bindCache();
 }
 }

 

本文作者:IT实验室 来源:http://dotnet.chinaitlab.com/CSharp/739639.html
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读