• 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         }
  • 相关阅读:
    C语言输出颜色
    嵌入式Linux串口编程简介
    推荐:实现RTSP/RTMP/HLS/HTTP协议的轻量级流媒体框架,支持大并发连接请求
    嵌入式串口打印信息重定向到当前终端界面
    C、C++、boost、Qt在嵌入式系统开发中的使用
    LInux下Posix的传统线程示例
    Linux用C语言模拟‘ls‘命令
    关于Linux目录访问函数总结
    Inter内部指令--AVX编程基础
    SPECCPU2006测试(456测试小记)
  • 原文地址:https://www.cnblogs.com/wgx0428/p/3181307.html
Copyright © 2020-2023  润新知