This tutorial will show you how to Use Cache using ASP.NET 2.0 and C#.NET.

First, you need to import the System.Web.Caching namespace.

First, the Cache Calss is Implements the cache for a Web application. This class cannot be inherited. We use the btnLoginBetter_Click event to do the work. We then call the Class Cache to use Cache.Insert. The methods of Cache.Insert is Overloaded and Inserts an item into the Cache object. Use one of the versions of this method to overwrite an existing Cache item with the same key parameter. After cache login status into memory, we use TimeSpan to destroy login status within one minutes. A TimeSpan object represents a time interval, or duration of time, measured as a positive or negative number of days, hours, minutes, seconds, and fractions of a second. The largest unit of time used to measure duration is a day. Time intervals are measured in days for consistency because the number of days in larger units of time, such as months and years, varies.

The front end Default.aspx page looks something like this:

The flow for the code behind page is as follows.

Download Source Files