ASP.Net使用缓存技术提高效率
来源:互联网 发布:淘宝店铺免费推广软件 编辑:程序博客网 时间:2024/06/06 04:15
一、在页面中显示时,读缓存数据,加载XML数据
public void LoadData()
{
DataView Source = (DataView)Cache["MyData"];
if(Source == null)
{
DataSet ds = new DataSet();
FileStream fs = new FileStream(Server.MapPath("LoginMsg.xml"), FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
fs.Close();
Source = new DataView(ds.Tables[0]);
Cache.Insert("MyData", Source, new CacheDependency(Server.MapPath("LoginMsg.xml")));
ErrorMsg.Text = "从文件中读取的数据";
}
else
{
ErrorMsg.Text = "从缓存中读取的数据";
}
MyDataGrid.DataSource = Source;
MyDataGrid.DataBind();
}
二、用XML存储交互数据,将数据放置到缓存中
private void LoginMsg_Click(object sender, System.EventArgs e)
{
if(!Page.IsValid)
{
ErrorMsg.Text = "必需输入登录信息";
return;
}
DataSet ds = new DataSet();
FileStream fs = new FileStream(Server.MapPath("LoginMsg.xml"),FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
fs.Close();
DataTable dt = ds.Tables[0];
DataRow newrow = dt.NewRow();
newrow["custom_email"] = CustomEamil.Text;
newrow["custom_pass"] = CustomPass.Text;
newrow["login_time"] = DateTime.Now.ToString();
fs = new FileStream(Server.MapPath("LoginMsg.xml"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
TextWriter writer = new StreamWriter(fs);
writer = TextWriter.Synchronized(writer);
ds.Tables[0].Rows.Add(newrow);
ds.WriteXml(writer);
writer.Close();
Cache.Remove("MyData");
LoadData();
}
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>- ASP.Net使用缓存技术提高效率
- ASP.Net使用缓存技术提高效率
- ASP.Net使用缓存技术提高效率
- 使用缓存技术提高效率
- ASP.NET 缓存技术
- asp.net 缓存技术
- asp.net 缓存技术
- asp.net 缓存技术
- ASP.NET 缓存技术
- asp.net缓存技术
- asp.Net 缓存技术
- ASP.NET-缓存技术
- ASP.NET 2.0 缓存技术
- ASP.NET 2.0 缓存技术
- ASP.NET的缓存技术
- asp.net页面缓存技术
- asp.net页面缓存技术
- asp.net页面缓存技术
- Asp.net自动返回上次请求页面
- 利用WebClient获取远程数据(仅做备份)
- 通过代码给IIS增加主机头
- 根据自定义字符串来缓存(部分)页面
- Repeater读取数据并分页
- ASP.Net使用缓存技术提高效率
- 使用asp.net进行多关键字查询的例子
- IBatisNet系列-执行存储过程
- .NET正则表达式使用高级技巧之反向引用
- 实现.NET应用程序的自动更新
- ASP.NET无限分类
- .NET下正则表达式应用的四个示例
- Asp.net前后台值的调用
- .NET正则表达式使用高级技巧之组的概念