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

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。