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

296人浏览 / 0人评论
复制代码 代码如下:

using System.Collections.Generic;
using System.Web;
using System;
namespace DataAccess
{
///
/// 缓存控制类
///
public class CacheControl
{
public static List AllUseCacheKey = new List();
///
/// 添加缓存
///
///
///
///
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);
}
///
/// 移除缓存
///
///
public static void RemoveCache(string key)
{
if (AllUseCacheKey.Contains(key))
{
AllUseCacheKey.Remove(key);
}
HttpContext.Current.Cache.Remove(key);
}
///
/// 清空使用的缓存
///
public static void ClearCache()
{
foreach (string value in AllUseCacheKey)
{
HttpContext.Current.Cache.Remove(value);
}
AllUseCacheKey.Clear();
}
}
}

全部评论

晴天下起了小雨
2017-10-01 18:00
很喜欢,果断关注了
wjmyly7336064
2017-10-01 18:00
相当实用,赞美了
橘大佬
2017-10-01 18:00
就是有些细节再到位点就好了…