<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="SimpleDataCache" %>
Untitled Page
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class SimpleDataCache : System.Web.UI.Page
{
protected void Page_Load(Object sender, EventArgs e)
{
if (this.IsPostBack)
{
lblInfo.Text += "Page posted back.
";
}
else
{
lblInfo.Text += "Page created.
";
}
if (Cache["TestItem"] == null)
{
DateTime testItem = DateTime.Now;
lblInfo.Text += "cache for 30 seconds.
";
Cache.Insert("TestItem", testItem, null,DateTime.Now.AddSeconds(30), TimeSpan.Zero);
}
else
{
lblInfo.Text += "Retrieving TestItem...
";
DateTime testItem = (DateTime)Cache["TestItem"];
lblInfo.Text += "TestItem is '" + testItem.ToString();
}
}
}