zoukankan      html  css  js  c++  java
  • 缓存类

     1    /// <summary>
     2     /// .net自带缓存类
     3     /// </summary>
     4     public class Cache : Interface.ICache
     5     {
     6         public static object LockObject = new object();
     7         private System.Web.Caching.Cache cache = HttpContext.Current.Cache;
     8         /// <summary>
     9         /// 插入缓存
    10         /// </summary>
    11         /// <param name="key"></param>
    12         /// <param name="obj"></param>
    13         /// <returns></returns>
    14         public bool Insert(string key, object obj)
    15         {
    16             if (obj == null) return false;
    17             lock (LockObject)
    18             {
    19                 cache.Insert(key, obj, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration);
    20             }
    21             return true;
    22         }
    23         /// <summary>
    24         /// 插入缓存
    25         /// </summary>
    26         /// <param name="key"></param>
    27         /// <param name="obj"></param>
    28         /// <returns></returns>
    29         public bool Insert(string key, object obj, DateTime expiry)
    30         {
    31             if (obj == null) return false;
    32             lock (LockObject)
    33             {
    34                 cache.Insert(key, obj, null, expiry, System.Web.Caching.Cache.NoSlidingExpiration,
    35                     System.Web.Caching.CacheItemPriority.Normal, null);
    36             }
    37             return true;
    38         }
    39         /// <summary>
    40         /// 获取缓存
    41         /// </summary>
    42         /// <param name="key"></param>
    43         /// <returns></returns>
    44         public object Get(string key)
    45         {
    46             return cache.Get(key);
    47         }
    48         /// <summary>
    49         /// 移出缓存
    50         /// </summary>
    51         /// <param name="key"></param>
    52         public bool Remove(string key)
    53         {
    54             object lockObj = new object();
    55             lock (lockObj)
    56             {
    57                 cache.Remove(key);
    58             }
    59             return true;
    60         }
    61         /// <summary>
    62         /// 移出所有缓存
    63         /// </summary>
    64         /// <returns></returns>
    65         public void RemoveAll()
    66         {
    67             for (int i = 0; i < cache.Count; i++)
    68             { 
    69                 
    70             }
    71         }
    72     }
  • 相关阅读:
    JS和jQuery获取节点的兄弟,父级,子级元素
    HTTP协议详解
    HTML5自定义属性对象Dataset
    当你输入一个网址后都发生什么
    javascript实现ajax
    第一次项目总结
    CSS简单布局总结
    animate.css总结
    自定义动画
    CSS 第四天 多重背景 变形 过渡
  • 原文地址:https://www.cnblogs.com/xiangzhong/p/5008426.html
Copyright © 2011-2022 走看看