使用ASP.NET 的缓存机制的示例

if (HttpContext.Current.Cache["code_" + CodeType] == null)
{
  SysCodeService codeService = new SysCodeService();
  List<SysCodeInfo> allCode = codeService.GetCodeListByFlag(CodeType); HttpContext.Current.Cache.Add("code_" + CodeType, allCode, null, DateTime.MaxValue, new TimeSpan(0, 10, 0), System.Web.Caching.CacheItemPriority.Default, null)
}
var dataSource = ((List<SysCodeInfo>)HttpContext.Current.Cache["code_" + CodeType]);

对业务类查询的结果缓存10分钟,如果10分钟之内再次访问,直接读取缓存中的数据

 

posted @ 2015-05-12 09:18  巴别塔  阅读(187)  评论(0编辑  收藏  举报