.NET Cache緩存



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

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM