protected void Application_Start(object sender, EventArgs e) { AccessProvider provider = new AccessProvider(); string fielPath = Server.MapPath("~/Xml/Student.xml"); List <Student> list = provider.GetStudentList(fielPath); System.Web.Caching.Cache cache = HttpRuntime.Cache; cache.Insert("Items1", list, new System.Web.Caching.CacheDependency(fielPath)); }
protected void Page_Load(object sender, EventArgs e) { List <Student> list = Cache["Items1"] as List <Student>; if (list != null && list.Count > 0) { list.ForEach(item => { Response.Write(item.Name + " " + item.Age + " " + item.Sex + "<br/>"); }); } else { AccessProvider provider = new AccessProvider(); string fielPath = Server.MapPath("~/Xml/Student.xml"); list = provider.GetStudentList(fielPath); Cache.Insert("Items1", list, new System.Web.Caching.CacheDependency(fielPath)); } }