-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheHandle.cs
More file actions
48 lines (44 loc) · 1.47 KB
/
CacheHandle.cs
File metadata and controls
48 lines (44 loc) · 1.47 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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Caching;
namespace PersistentWebService
{
public class CacheHandle
{
private const string DummyCacheItemKey = "__DummyCacheItemKey_";
public static void RegisterCacheEntry(string url)
{
RegisterCacheEntry(url, 5);
RegisterCacheEntry(url, 7);
RegisterCacheEntry(url, 11);
}
private static void RegisterCacheEntry(string url, int minutes)
{
if (HttpContext.Current.Cache[DummyCacheItemKey + minutes] == null)
{
HttpContext.Current.Cache.Add(DummyCacheItemKey + minutes, url, null, Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(minutes), CacheItemPriority.NotRemovable, CacheItemRemovedCallback);
}
}
// 缓存项过期时程序模拟点击页面,阻止应用程序结束
private static void CacheItemRemovedCallback(string key, object value, CacheItemRemovedReason reason)
{
try
{
using (System.Net.WebClient client = new System.Net.WebClient())
{
client.DownloadData(value.ToString());
}
}
catch (Exception ex)
{
Debug.Write(ex);
}
}
}
}