缓存

判断缓存是否存在

        if (HttpRuntime.Cache[key] == null)
        {
          
        }

插入缓存 缓存过期时间为2个小时

NoAbsoluteExpiration:相对过期时间,生成缓存后若在没有过期的时间段被取,则过期时间后推10分钟,例如:11:1分钟时生成的 在11:5分钟时被取了,则过期时间为11:15分钟

HttpRuntime.Cache.Insert(key.ToUpper(), dic, null,System.Web.Caching.Cache.NoAbsoluteExpiration,TimeSpan.FromMinutes(10));

NoSlidingExpiration:固定过期时间,2个小时后一定过期

HttpRuntime.Cache.Insert(key.ToUpper(), dic, null, DateTime.UtcNow.AddHours(2), System.Web.Caching.Cache.NoSlidingExpiration);

清空缓存

 HttpRuntime.Cache.Remove(key);

原文地址:https://www.cnblogs.com/ajun/p/2917535.html