源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

asp.net下Cache 缓存操作类代码

  • 时间:2021-11-11 16:13 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:asp.net下Cache 缓存操作类代码
[u]复制代码[/u] 代码如下:
using System.Collections.Generic; using System.Web; using System; namespace DataAccess { /// <summary> /// 缓存控制类 /// </summary> public class CacheControl { public static List<string> AllUseCacheKey = new List<string>(); /// <summary> /// 添加缓存 /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="absoluteExpiration"></param> public static void AddCache(string key, object value, DateTime absoluteExpiration) { if (!AllUseCacheKey.Contains(key)) { AllUseCacheKey.Add(key); } HttpContext.Current.Cache.Add(key, value, null, absoluteExpiration, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null); } /// <summary> /// 移除缓存 /// </summary> /// <param name="key"></param> public static void RemoveCache(string key) { if (AllUseCacheKey.Contains(key)) { AllUseCacheKey.Remove(key); } HttpContext.Current.Cache.Remove(key); } /// <summary> /// 清空使用的缓存 /// </summary> public static void ClearCache() { foreach (string value in AllUseCacheKey) { HttpContext.Current.Cache.Remove(value); } AllUseCacheKey.Clear(); } } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部