public void pro_ShowBook_tw(HttpContext context)
{
DataTable dt = null;
string cacheKey = "GetList"; ///唯一的key值
if (HttpContext.Current.Cache[cacheKey] == null) ///是否存在
{
dt = BLL.BLL_Activity2019.pro_ShowBook_tw(); ///不存在,查询数据
if (dt.Rows.Count > 0)
{
HttpContext.Current.Cache.Insert(cacheKey, dt, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration);// 缓存10分钟
}
}
else
{
dt = (DataTable)HttpContext.Current.Cache[cacheKey]; ///存在查询缓存
}
string result = JsonConvert.SerializeObject(new{data = new { list = dt }});转换成json
context.Response.Write(result);
}