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         }
  • 相关阅读:
    Linux系统模拟端口开放程序port 软件的基本使用
    Docker19.03.13离线安装-Docker根目录-Docker常用操作--NVIDIA Docker
    springboot项目启动与停止命令
    两种设备选型的主要性能指标
    docker nginx配置
    使用shell+java 抓取NHK广播
    小程序的测试方法
    adb logcat 查看Android APP日志
    IE11判断是否全是中文的时候无效写法
    C#控制器微信通过encryptedData,iv,Code获取用户信息
  • 原文地址:https://www.cnblogs.com/wgx0428/p/3181307.html
Copyright © 2011-2022 走看看