1: public class MyCacheInfo
2: {
3: public string Url
4: {
5: get;
6: set;
7: }
8: public object MyValue
9: {
10: get;
11: set;
12: }
13: }
14:
15:
16: static string _myObject = "MyObject";
17: static CacheItemRemovedCallback onRemove = new CacheItemRemovedCallback(RemoveCallback);
18:
19: public static void RemoveCallback(string k, Object v, CacheItemRemovedReason r)
20: {
21: MyCacheInfo info = v as MyCacheInfo;
22:
23: WebClient net = new WebClient();
24: net.DownloadData(info.Url.Replace("?Al=1","") + "?Al=1");
25:
26: }
27:
28: protected void Page_Load(object sender, EventArgs e)
29: {
30: if (Request.Params["Al"] != null)
31: {
32: DateTime dtExpiration = DateTime.UtcNow.AddSeconds(10);
33:
34: MyCacheInfo info = new MyCacheInfo()
35: {
36: MyValue = DateTime.Now,
37: Url = HttpContext.Current.Request.Url.OriginalString
38: };
39: Cache.Add(_myObject,
40: info,
41: null,
42: dtExpiration,
43: System.Web.Caching.Cache.NoSlidingExpiration,
44: System.Web.Caching.CacheItemPriority.High,
45: onRemove);
46: }
47: }
48:
49:
50: protected void Button1_Click(object sender, EventArgs e)
51: {
52: // Add everything here
53: Session[_myObject] = TextBoxSession.Text;
54: Application[_myObject] = TextBoxApplication.Text;
55:
56:
57: MyCacheInfo info = new MyCacheInfo()
58: {
59: MyValue = TextBoxCache.Text,
60: Url = HttpContext.Current.Request.Url.OriginalString
61: };
62:
63: DateTime dtExpiration = DateTime.UtcNow.AddSeconds(10);
64: Cache.Add(_myObject,
65: TextBoxCache.Text,
66: null,
67: dtExpiration,
68: System.Web.Caching.Cache.NoSlidingExpiration,
69: System.Web.Caching.CacheItemPriority.High,
70: onRemove);
71:
72: }
73:
74:
75:
76: protected void Button2_Click(object sender, EventArgs e)
77: {
78: //Retrive
79: if (Session[_myObject] != null)
80: LabelSession.Text = Session[_myObject].ToString();
81: else
82: LabelSession.Text = "No Session";
83:
84: if (Application[_myObject] != null)
85: LabelApplication.Text = Application[_myObject].ToString();
86: else
87: LabelApplication.Text = "No Application";
88:
89: if (Cache[_myObject] != null)
90: LabelCache.Text = Cache[_myObject].ToString();
91: else
92: LabelCache.Text = "No Cache";
93: }
94:
95: }