Repository navigation
Expand file tree
/
Copy pathCache.cs
More file actions
83 lines (81 loc) · 2.36 KB
/
Copy pathCache.cs
File metadata and controls
83 lines (81 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Caching;
namespace MyCache.InProc
{
/// <summary>
/// .net自带缓存类
/// </summary>
public class Cache : Interface.ICache
{
private System.Web.Caching.Cache cache = HttpContext.Current.Cache;
/// <summary>
/// 插入缓存
/// </summary>
/// <param name="key"></param>
/// <param name="obj"></param>
/// <returns></returns>
public bool Insert(string key, object obj)
{
if (obj == null) return false;
object lockObj = new object();
lock (lockObj)
{
cache.Insert(key, obj, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration);
}
return true;
}
/// <summary>
/// 插入缓存
/// </summary>
/// <param name="key"></param>
/// <param name="obj"></param>
/// <returns></returns>
public bool Insert(string key, object obj, DateTime expiry)
{
if (obj == null) return false;
object lockObj = new object();
lock (lockObj)
{
cache.Insert(key, obj, null, expiry, System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Normal, null);
}
return true;
}
/// <summary>
/// 获取缓存
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public object Get(string key)
{
return cache.Get(key);
}
/// <summary>
/// 移出缓存
/// </summary>
/// <param name="key"></param>
public bool Remove(string key)
{
object lockObj = new object();
lock (lockObj)
{
cache.Remove(key);
}
return true;
}
/// <summary>
/// 移出所有缓存
/// </summary>
/// <returns></returns>
public void RemoveAll()
{
for (int i = 0; i < cache.Count; i++)
{
}
}
}
}