zoukankan      html  css  js  c++  java
  • CacheHelper.cs(20170223)

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web;
    using System.Web.Caching;
    
    namespace System.CRM.Common
    {
        /// <summary>
        /// 缓存操作助手类
        /// </summary>
        public class CacheHelper
        {
            /// <summary>
            /// 获取数据缓存
            /// </summary>
            /// <param name="key">Cache的Key值</param>
            public static object GetCache(string key)
            {
                return HttpRuntime.Cache.Get(key);
            }
    
            /// <summary>
            /// 设置数据缓存
            /// </summary>
            /// <param name="key">Cache的Key值</param>
            /// <param name="value">Cache的Value值</param>
            public static void SetCache(string key, object value)
            {
                HttpRuntime.Cache.Insert(key, value);
            }
    
            /// <summary>
            /// 设置数据缓存
            /// </summary>
            /// <param name="key">Cache的Key值</param>
            /// <param name="value">Cache的Value值</param>
            /// <param name="timeout">最后一次访问Cache超过该时间间隔,则该Cache会被移除</param>
            public static void SetCache(string key, object value, TimeSpan timeout)
            {
                Cache objCache = HttpRuntime.Cache;
                objCache.Insert(key, value, null, DateTime.MaxValue, timeout, CacheItemPriority.NotRemovable, null);
            }
    
            /// <summary>
            /// 设置数据缓存
            /// </summary>
            /// <param name="key">Cache的Key值</param>
            /// <param name="value">Cache的Value值</param>
            /// <param name="absolute">超时时间(单位:天)</param>
            /// <param name="timeout">最后一次访问Cache超过该时间间隔,则该Cache会被移除</param>
            public static void SetCache(string key, object value, double absolute, TimeSpan timeout)
            {
                Cache objCache = HttpRuntime.Cache;
                objCache.Insert(key, value, null, DateTime.UtcNow.AddDays(absolute), timeout);
            }
    
            /// <summary>
            /// 移除指定数据缓存
            /// </summary>
            /// <param name="key">Cache的Key值</param>
            public static void RemoveCache(string key)
            {
                HttpRuntime.Cache.Remove(key);
            }
    
            /// <summary>
            /// 移除全部缓存
            /// </summary>
            public static void RemoveAllCache()
            {
                Cache cache = HttpRuntime.Cache;
                IDictionaryEnumerator ide = cache.GetEnumerator();
                while (ide.MoveNext())
                {
                    cache.Remove(ide.Key.ToString());
                }
            }
        }
    
    }
  • 相关阅读:
    【方法1】删除Map中Value反复的记录,而且仅仅保留Key最小的那条记录
    hdu3415 Max Sum of Max-K-sub-sequence 单调队列
    HBase总结(十八)Hbase rowkey设计一
    Makefile生成器,使用C++和Boost实现
    quartz cron表达式在线生成
    NS3网络仿真(6): 总线型网络
    连载:面向对象葵花宝典:思想、技巧与实践(35)
    zoj 2921 Stock(贪心)
    11g RAC 加节点 之 手动加入vip 资源
    [Unity3D]Unity+Android交互教程——让手机&quot;动&quot;起来
  • 原文地址:https://www.cnblogs.com/zyx321/p/6435838.html
Copyright © 2011-2022 走看看