If (! IsPostBack) // load for the first time
{
Stopwatch watch = new Stopwatch (); // defines the cache.
Watch. Start ();
If (Cache ["grda"] = null) // if the cache is empty
{
GRDA grda = new GRDA ();
DataTable dt = grda. GetGrda (); // obtain database information
// The easiest way to assign values to the cache
Cache ["grda"] = dt;
// You can set the cache value Assignment Method for the expiration time
Cache. Insert ("grda", dt, null, DateTime. Now. AddSeconds (30), TimeSpan. Zero );
// Create an associated file
CacheDependency file = new CacheDependency ("c: \ 11.txt ");
Cache. Insert ("grda", dt, file, DateTime. Now. AddMinutes (30), TimeSpan. Zero );
// (Cache name, Data, associated file, session time, click to add a ten-minute validity period (generally not used ))
}
This. GridView1.DataSource = (DataTable) Cache ["grda"]; // retrieves data from the Cache
This. GridView1.DataBind ();
Watch. Stop (); // Stop caching
Double totaltime = watch. Elapsed. TotalSeconds;
This. Label1.Text = totaltime. ToString (); // display the expiration time
// The above analysis is personal opinion. If there are differences, please add Q472613400 for discussion.
From the liuningshiwoa Column