使用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分钟之内再次访问,直接读取缓存中的数据

 

你可能感兴趣的:(asp.net)