The original Published time: 2008-08-01--from my Baidu article [imported by moving tools]
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;
Using System.Data.SqlClient;
public partial class Cacheds:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
DataSet ds= (DataSet) Cache.get ("Ds_cache");
if (! IsPostBack)
{
if (ds = = null)
{
SqlConnection conn = new SqlConnection (configurationmanager.connectionstrings["PubsConn"]. ConnectionString);
SqlDataAdapter SDA = new SqlDataAdapter ();
Sda. SelectCommand = new SqlCommand ("Select Title_id,title,type from Titles", Conn);
DataSet CDs = new DataSet ();
Sda. Fill (CDs, "T1");
Cds. Extendedproperties.add ("Ds_t1", DateTime.Now.ToLongTimeString ());
Cache.Insert ("Ds_cache", CDs, NULL, DateTime.Now.AddMinutes (2), TimeSpan.Zero);
Response.Write (" Object has been populated from the database and stored in the cache ");
Gridview1.datasource = CDs. tables["T1"];
Gridview1.databind ();
}
Else
{
Response.Write ("object is also cached in cache, call directly");
Gridview1.datasource = ds. tables["T1"];
Gridview1.databind ();
}
}
}
protected void Button1_Click (object sender, EventArgs e)
{
Cache.remove ("Ds_cache");
}
}
Ado:dataset Cache and use the