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 }