加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 20:35:39 所属栏目:asp.Net 来源:网络整理
导读:复制代码 代码如下: using System.Collections.Generic; using System.Web; using System; namespace DataAccess { /// summary /// 缓存控制类 /// /summary public class CacheControl { public static Liststring AllUseCacheKey = new Liststring(); ///
复制代码 代码如下:

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();
}
}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读