设置缓存

先定义一个缓存变量

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值