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         }
  • 相关阅读:
    DAY7-面向对象之封装
    Java遇到的问题、错误——持续更新
    008单例、继承、final
    java一些使用
    2.1端口扫描器
    PyCharm设置
    常用算法
    PyCharm最新2018激活码,最新方法
    004数组
    042多进程
  • 原文地址:https://www.cnblogs.com/wgx0428/p/3181307.html
Copyright © 2011-2022 走看看