asp.net下Cache 缓存操作类代码
asp.net下Cache 缓存操作类代码
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:usingSystem.Collections.Generic;usingSystem.Web;usingSystem;n...

复制代码 代码如下:

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

}

}

}

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新asp.net教程学习
热门asp.net教程学习
编程开发子分类