缓存命中代码
//绑定数据 firstLoad 是否是第一次加载数据和缓存失效. protected void BindList(bool firstLoad) { DataSet data = new DataSet(); //第一次加载数据. if (firstLoad) { //转换编码,防止汉字出现乱码. string codeKeyword = HttpUtility.UrlEncode(strKeywords); string codeCityDest = HttpUtility.UrlEncode(strCityDest); cacheId = codeKeyword + codeCityDest + strReqObj; hdnCacheId.Value = cacheId; Cache.Insert(cacheId, ds, null, DateTime.Now.AddSeconds(30), TimeSpan.Zero); pageBind(ds); pageBindForNew(ds); } //翻页加载数据. else { cacheId = hdnCacheId.Value; DataSet cacheDataSet = (DataSet)Cache[cacheId]; //缓存命中,则使用缓存数据. if (cacheDataSet != null) { pageBind(cacheDataSet); pageBindForNew(cacheDataSet); } //缓存失效,则重新通过http加载数据. else { pageload(); } } }