文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Cache 缓存操作类

Cache 缓存操作类

时间:2011-03-18  来源:如歌

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

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载