/
DictionaryCache.cs
43 lines (38 loc) · 1.04 KB
/
DictionaryCache.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
using System.Collections.Generic;
namespace DeviceDetector.NET.Cache
{
public class DictionaryCache : ICache
{
private static Dictionary<string,object> _staticCache = new Dictionary<string, object>();
public bool Contains(string id)
{
return _staticCache !=null && _staticCache.Keys.Count > 0 && _staticCache.ContainsKey(id);
}
public bool Delete(string id)
{
_staticCache.Remove(id);
return true;
}
public object Fetch(string id)
{
return Contains(id) ? _staticCache[id] : null;
}
public bool FlushAll()
{
_staticCache = new Dictionary<string, object>();
return true;
}
public bool Save(string id, object data, int lifeTime = 0)
{
if (Contains(id))
{
_staticCache[id] = data;
}
else
{
_staticCache.Add(id, data);
}
return true;
}
}
}