public ActionResult Index()
{
int id = (int)(Session["User"] as Sys_User).Usr_Id;
string cachekey = id.ToString();//可随意输入
List<Cst_Customer> list = (List<Cst_Customer>)HttpContext.Cache[cachekey];
if (list == null)
{
list = cstCustomerManager.GetCustomersByUserId(id);
HttpContext.Cache.Insert(cachekey, list,null, DateTime.Now.AddMinutes(1), TimeSpan.Zero);//第一个参数是键,第二个是值,第四个参数是时间,其他参数可直接为空
}
return View(list);
}
asp.net内置缓存cache在MVC中的存取简单案例
最新推荐文章于 2022-04-08 09:25:37 发布