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     }
  • 相关阅读:
    全面理解面向对象的 JavaScript
    账号
    移动端 前端框架 amaze ui
    javascript 精典案例分析一览
    前端事件系统(一)
    周总结12
    周总结11
    相比较于其他的同类软件
    团队冲刺第十五天
    团队冲刺第十四天
  • 原文地址:https://www.cnblogs.com/xiangzhong/p/5008426.html
Copyright © 2011-2022 走看看