forked from xuxiaowei007/FoxOne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemCache.cs
55 lines (48 loc) · 1.21 KB
/
MemCache.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FoxOne.Core
{
public class MemCache : ICache
{
private static IDictionary<string, object> cache = new Dictionary<string, object>();
public IList<string> AllKeys
{
get
{
return cache.Keys.ToList();
}
}
public void Clean()
{
foreach (var key in AllKeys)
{
cache.Remove(key);
}
}
public object GetValue(string key)
{
if (cache.Keys.Contains(key))
{
return cache[key];
}
return null;
}
public void Remove(string key)
{
if (cache.Keys.Contains(key))
{
cache.Remove(key);
}
}
public void SetValue(string key, object value)
{
cache[key] = value;
}
public void SetValue(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration)
{
SetValue(key, value);
}
}
}