ASP.Net's caching technology has greatly improved efficiency. I will post the simple implementation code of the code:
1. When displaying on the page, read the cached data and load the XML data
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 = "Data read from file";
}
else
{
ErrorMsg.Text = "Data read from cache";
}
MyDataGrid.DataSource = Source;
MyDataGrid.DataBind();
}
2. Use XML to store interactive data and place the data in the cache
private void LoginMsg_Click(object sender, System.EventArgs e)
{
if(!Page.IsValid)
{
ErrorMsg.Text = "Login information required";
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();
}