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);
}