Repository navigation
Expand file tree
/
Copy pathSystemWebProvider.cs
More file actions
70 lines (62 loc) · 1.75 KB
/
Copy pathSystemWebProvider.cs
File metadata and controls
70 lines (62 loc) · 1.75 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
using System;
using System.Web;
namespace CacheCSharp
{
public class SystemWebProvider : CacheProviderBase<System.Web.Caching.Cache>
{
protected override System.Web.Caching.Cache InitCache()
{
return HttpRuntime.Cache;
}
public override T Get<T>(string key)
{
try
{
if (!Exists(key))
{
return default(T);
}
return (T)Cache[KeyPrefix+key];
}
catch
{
return default(T);
}
}
public override void Set<T>(string key, T value, int duration)
{
Cache.Insert(
KeyPrefix + key,
value,
null,
System.Web.Caching.Cache.NoAbsoluteExpiration,
new TimeSpan(0, duration, 0));
}
public override void SetSliding<T>(string key, T value, int duration)
{
Cache.Insert(
KeyPrefix+key,
value,
null,
DateTime.Now.AddMinutes(duration),
System.Web.Caching.Cache.NoSlidingExpiration);
}
public override void Set<T>(string key, T value, DateTimeOffset expiration)
{
Cache.Insert(
KeyPrefix + key,
value,
null,
expiration.DateTime,
System.Web.Caching.Cache.NoSlidingExpiration);
}
public override bool Exists(string key)
{
return Cache[KeyPrefix + key] != null;
}
public override void Remove(string key)
{
Cache.Remove(KeyPrefix+key);
}
}
}