zoukankan      html  css  js  c++  java
  • C#自带缓存方案

     1         /// <summary>
     2         /// 获取数据缓存
     3         /// </summary>
     4         /// <param name="CacheKey"></param>
     5         public static object GetCache(string CacheKey)
     6         {
     7             System.Web.Caching.Cache objCache = HttpRuntime.Cache;
     8             return objCache[CacheKey];
     9         }
    10         /// <summary>
    11         /// 设置数据缓存
    12         /// </summary>
    13         public static void SetCache(string CacheKey, object objObject)
    14         {
    15             System.Web.Caching.Cache objCache = HttpRuntime.Cache;
    16             objCache.Insert(CacheKey, objObject);
    17         }
    18         /// <summary>
    19         /// 设置数据缓存
    20         /// </summary>
    21         public static void SetCache(string CacheKey, object objObject, TimeSpan Timeout)
    22         {
    23             System.Web.Caching.Cache objCache = HttpRuntime.Cache;
    24             objCache.Insert(CacheKey, objObject, null, DateTime.MaxValue, Timeout, System.Web.Caching.CacheItemPriority.NotRemovable, null);
    25         }
    26         /// <summary>
    27         /// 设置数据缓存
    28         /// </summary>
    29         public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
    30         {
    31             System.Web.Caching.Cache objCache = HttpRuntime.Cache;
    32             objCache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
    33         }
    34         /// <summary>
    35         /// 移除指定数据缓存
    36         /// </summary>
    37         public static void RemoveAllCache(string CacheKey)
    38         {
    39             System.Web.Caching.Cache _cache = HttpRuntime.Cache;
    40             _cache.Remove(CacheKey);
    41         }
    42         /// <summary>
    43         /// 移除全部缓存
    44         /// </summary>
    45         public static void RemoveAllCache()
    46         {
    47             System.Web.Caching.Cache _cache = HttpRuntime.Cache;
    48             IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
    49             while (CacheEnum.MoveNext())
    50             {
    51                 _cache.Remove(CacheEnum.Key.ToString());
    52             }
    53         }
  • 相关阅读:
    学习UML类图
    【转】监听器(Listener)学习
    【转】ContextLoaderListener和DispatcherServlet加载内容的区别
    个人B站+微信公众号
    如何直观形象地树状打印一棵二叉树?
    轻松手撕10大排序算法
    简单易懂的快速幂取模算法
    程序员必学:快速幂算法
    为什么Swift和Python要抛弃++--?
    JetBrains系列IDE的配色方案(IDEACLionPyCharm)
  • 原文地址:https://www.cnblogs.com/wgx0428/p/3181307.html
Copyright © 2011-2022 走看看