zoukankan      html  css  js  c++  java
  • CacheHelper

    private List<MENU> _Menu; 
    public List<MENU> Menu
    {
        get
        {
            if (_Menu == null)
            {
                if (!CacheHelper.IsSet("menus"))
                { 
                    CacheHelper.Set("menus", BllSession.IMENU_BLL.GetListByWhere(s => s.IsDel == 0));
                }
                var menus = Menus.Select(s => s.MENUID);
                _Menu = CacheHelper.Get<List<MENU>>("menus").Where(s => menus.Contains(s.MENUID)).ToList();
            }
            return _Menu;
        } 
    }
     1 public class CacheHelper
     2 {
     3     static System.Web.Caching.Cache Cache = HttpRuntime.Cache;
     4 
     5     public static void Set(string key, object data)
     6     {
     7         Cache.Insert(key, data);
     8     }
     9 
    10     public static void Set(string key, object data, DateTime absoluteExpiration)
    11     {
    12         Cache.Insert(key, data, null, absoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration);
    13     }
    14 
    15     public static void Set(string key, object data, TimeSpan slidingExpiration)
    16     {
    17         Cache.Insert(key, data, null,System.Web.Caching.Cache.NoAbsoluteExpiration, slidingExpiration);
    18     }
    19      
    20 
    21     public static void Set(string key, object data, string fileName)
    22     {
    23         Cache.Insert(key, data, new System.Web.Caching.CacheDependency(fileName)); 
    24     }
    25      
    26     public static void Set(string key, object data,System.Web.Caching.CacheItemRemovedCallback callback)
    27     {
    28         Cache.Insert(key, data, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, callback); 
    29     }
    30 
    31     public static void Set(string key, object data, System.Web.Caching.CacheItemUpdateCallback callback)
    32     {
    33         Cache.Insert(key, data, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, callback);
    34     }
    35     
    36     public static object Get(string Key)
    37     {
    38         return Cache[Key];
    39     }
    40 
    41     public static T Get<T>(string key)
    42     {
    43         return (T)Cache[key];
    44     }
    45 
    46     public static bool IsSet(string key)
    47     {
    48         return Cache[key] != null;
    49     }
    50 
    51     public static void Remove(string Key)
    52     {
    53         if (Cache[Key] != null)
    54         {
    55             Cache.Remove(Key);
    56         }
    57     }
    58 
    59     public static void RemoveByPattern(string pattern)
    60     {
    61         IDictionaryEnumerator enumerator = Cache.GetEnumerator();
    62         Regex rgx = new Regex(pattern, (RegexOptions.Singleline | (RegexOptions.Compiled | RegexOptions.IgnoreCase)));
    63         while (enumerator.MoveNext())
    64         {
    65             if (rgx.IsMatch(enumerator.Key.ToString()))
    66             {
    67                 Cache.Remove(enumerator.Key.ToString());
    68             }
    69         }
    70     }
    71 
    72     public static void Clear()
    73     {
    74         IDictionaryEnumerator enumerator = Cache.GetEnumerator();
    75         while (enumerator.MoveNext())
    76         {
    77             Cache.Remove(enumerator.Key.ToString());
    78         }
    79     }
    80 }
    81  
    CacheHelper
  • 相关阅读:
    POJ 3259 Wormholes【BellmanFord】
    POJ 2960 SNim【SG函数的应用】
    ZOJ 3578 Matrixdp水题
    HDU 2897 邂逅明下【bash博弈】
    BellmanFord 算法及其优化【转】
    【转】几个Java的网络爬虫
    thinkphp 反字符 去标签 自动加点 去换行 截取字符串 冰糖
    php 二维数组转 json文本 (jquery datagrid 数据格式) 冰糖
    PHP 汉字转拼音(首拼音,所有拼音) 冰糖
    设为首页与加入收藏 兼容firefox 冰糖
  • 原文地址:https://www.cnblogs.com/valeb/p/7634528.html
Copyright © 2011-2022 走看看