亲宝软件园·资讯

展开

Asp.Net Cache Asp.Net Cache缓存使用代码

人气:0
想了解Asp.Net Cache缓存使用代码的相关内容吗,在本文为您仔细讲解Asp.Net Cache的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Asp.Net,Cache,缓存,下面大家一起来学习吧。
复制代码 代码如下:

public DataSet createCache()
{
//返回DataSet
DataSet ds=new DataSet();
OleDbConnection conn=new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source="+Server.MapPath("data.mdb"));
conn.Open();
string sql="select * from data1 order by createtime asc";
OleDbDataAdapter cmd=new OleDbDataAdapter(sql,conn);
cmd.Fill(ds);
cmd.Dispose();
conn.Dispose();
return ds;
}

private void Button1_Click(object sender, System.EventArgs e)
{
//清除Cache
Cache.Remove("DataList");
Response.Write("缓存清除成功");
}

private void Button2_Click(object sender, System.EventArgs e)
{
//建立Cache
if(Cache["DataList"]==null)
{
//缓存不存在建立缓存
Cache.Insert("DataList",(DataSet)createCache());
DataSet ds=(DataSet)Cache["DataList"];
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}
else
{
//缓存存在执行绑定
DataSet ds=(DataSet)Cache["DataList"];
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
}
}

加载全部内容

相关教程
猜你喜欢
用户评论