zoukankan      html  css  js  c++  java
  • CacheHelper

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.Caching;
    
    namespace ClusterService.Common
    {
        public static class CacheHelper
        {
            public static object Cache(string key)
            {
                return HttpRuntime.Cache[key];
            }
            public static void Cache(string key, object value)
            {
                HttpRuntime.Cache.Insert(key, value);
            }
            public static void Cache(string key, object value, DateTime utcDate)
            {
                HttpRuntime.Cache.Insert(key, value, null, utcDate, System.Web.Caching.Cache.NoSlidingExpiration);
            }
            public static void Cache(string key, object value, TimeSpan span)
            {
                HttpRuntime.Cache.Insert(key, value, null, System.Web.Caching.Cache.NoAbsoluteExpiration, span);
            }
            public static void Cache(string key, object value, DateTime utcDate, CacheItemPriority priority, CacheItemRemovedCallback callback)
            {
                HttpRuntime.Cache.Insert(key, value, null, utcDate, System.Web.Caching.Cache.NoSlidingExpiration, priority, callback);
            }
            public static void Cache(string key, object value, TimeSpan span, CacheItemPriority priority, CacheItemRemovedCallback callback)
            {
                HttpRuntime.Cache.Insert(key, value, null, System.Web.Caching.Cache.NoAbsoluteExpiration, span, priority, callback);
            }
    
            public static void Expire(string key)
            {
                var cache = HttpRuntime.Cache;
                if (cache[key] != null)
                {
                    cache.Remove(key);
                }
            }
    
            [Obsolete("谨慎使用")]
            public static void ExpireStartsWith(string key)
            {
                var cache = HttpRuntime.Cache;
                var tor = cache.GetEnumerator();
                while (tor.MoveNext())
                {
                    string itemKey = tor.Key.ToString();
                    if (itemKey.StartsWith(key))
                    {
                        cache.Remove(itemKey);
                    }
                }
            }
        }
    }
  • 相关阅读:
    牛客 158F 青蛙 (贪心)
    牛客 158D a-贝利福斯数
    长沙理工大学第十二届ACM大赛-重现赛 大家一起来数二叉树吧 (组合计数)
    美团2017年CodeM大赛-初赛B轮 黑白树 (树形dp)
    美团2017年CodeM大赛-初赛A轮 C合并回文子串
    活动安排问题
    0和5
    1489 蜥蜴和地下室
    1067 Bash游戏 V2
    1062 序列中最大的数
  • 原文地址:https://www.cnblogs.com/Googler/p/2867370.html
Copyright © 2011-2022 走看看