This sample code shows the use of ASP.net caching technique.
Here is the code :
///caching example using cache object
//Store cache information
datasource = (System.Data.DataView)Cache["cacheds"];
if (datasource == null)
//Make a connection to database
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
string cmd = "select EmployeeNo,Name,Email from tab1";
SqlDataAdapter da = new SqlDataAdapter(cmd, conn);
DataSet ds = new DataSet();
ds.Locale = System.Globalization.CultureInfo.CurrentCulture;
datasource = new DataView(ds.Tables);
//store data into cache object for first time
Cache["cacheds"] = datasource;
Response.Write(" from Database");
//Disply data from cache
GridView1.DataSource = datasource;
catch (Exception ex)
I didn't get what type of caching example you given here.
Caching method is to improve the performance of application by using the application cache and to avoid unnecessary round trips to database.
It is a process of storing frequently used data on the server to fulfill subsequent requests.Caching helps us to achieve three important points namely PERFORMANCE,SCALABILITY,AVAILABILITY.