ASP.Net使用缓存技术提高效率
来源:互联网 发布:java 将两个list合并 编辑:程序博客网 时间:2024/05/18 17:24
ASP.Net的缓存技术大大地提高了效率,本人将代码的简单的实现代码贴出: 字串8
一、在页面中显示时,读缓存数据,加载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();
} 字串7
字串3
二、用XML存储交互数据,将数据放置到缓存中 字串4
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); 字串7
ds.Tables[0].Rows.Add(newrow);
ds.WriteXml(writer);
writer.Close();
Cache.Remove("MyData");
LoadData(); 字串7
} 字串9
- 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页面缓存技术
- JAVASCRIPT精彩200例
- TCPView(查看网络端口的程序)
- Asp.net前后台值的调用
- C#实现web信息自动抓取
- .net打包自动安装数据库
- ASP.Net使用缓存技术提高效率
- Asp.net自动返回上次请求页面
- Windows Mobile与symbian智能手机系统的比较
- C++局部类和嵌套类的区别
- 编程体会
- 绝对经典的滑轮新闻显示(javascript+css)
- 2006年上半年软件评测师试题及答案
- firefox中表单提交用submit()
- 《软件测试》 自动化测试学习笔记