您的当前位置:首页 >域名 >如何不使用数据库缓存,还达到实时更新 正文

如何不使用数据库缓存,还达到实时更新

时间:2025-11-05 07:09:24 来源:网络整理编辑:域名

核心提示

复制#region##根据条件得到新闻 ///<summary> ///根据条件得到新闻 ///</summa

如何不使用数据库缓存,还达到实时更新
复制#region##根据条件得到新闻 /// <summary> /// 根据条件得到新闻 /// </summary> /// <param name="tableName"></param> /// <param name="whereStr"></param> /// <param name="topCount"></param> /// <returns></returns> public List<CmsDemoModels.NewsInfo> GetByCondition(string whereStr,使用数据实 string topCount)        {   string cacheKey = string.Format(".{1}.{2}", GetType(), "GetByCondition",whereStr+topCount);   if (HttpRuntime.Cache[cacheKey] != null)            {   return HttpRuntime.Cache[cacheKey] as List<CmsDemoModels.NewsInfo>;            }   else          {   //从数据库里查找并插入缓存 using (CmsDemoDAL.NewsInfoServcie ns = new NewsInfoServcie())                {                    List<NewsInfo> newsList=ns.GetByCondition(whereStr, topCount);                    HttpRuntime.Cache.Insert(cacheKey,newsList, null, DateTime.Now.AddDays(1), TimeSpan.Zero);   return newsList;                }            }        }  1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.