先定义一个缓存变量
int cacheMinute = int.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["ModelCache"]); //缓存时间(分钟)
在需要设置缓存的上边写红色代码
string cacheKey = "kdp-newPro-" + pNum; object objCache = clsUtility.GetCache(cacheKey);
if (objCache == null) { string sort = ""; string strWhere = " where 1=1 and commlist.CTime>DateAdd(d,-20,getdate()) and vw.id1 in (1,2,3) "; string strSql = @"select top 740 row_number() over(order by commlist.ID) as r_n,commlist.p_name,commlist.pid,commlist.cur_price from Da_CommodityList commlist left join vw_Grading vw on commlist.catid=vw.id4 " + strWhere; //分页 dt1 = sys.GetRecordByPage(strSql, pNum, pSize, sort, out rCount, out pCount).Tables[0]; clsUtility.AddCache(cacheKey, dt1, cacheMinute); } else { dt1 = objCache as DataTable; } cacheKey = "kdp-newPro-rCount" + pNum; objCache = clsUtility.GetCache(cacheKey); if (objCache == null) { clsUtility.AddCache(cacheKey, rCount, cacheMinute); } else { rCount = int.Parse(objCache.ToString()); //八分页进行缓存,否则不会显示页码 } repNewPro.DataSource = dt1; repNewPro.DataBind();