ASP.Net caching

Description :
This sample code shows the use of ASP.net caching technique.

Here is the code :


///caching example using cache object
try
{
DataView datasource;
//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;
da.Fill(ds);
datasource = new DataView(ds.Tables[0]);
//store data into cache object for first time
Cache["cacheds"] = datasource;
Response.Write(" from Database");

}
else
{
//Disply data from cache
GridView1.DataSource = datasource;
GridView1.DataBind();
Response.Write("From cache");

}

}
catch (Exception ex)
{
Response.Write(ex.Message);

}
}


Comments

Author: Arun Kambhammettu14 Aug 2013 Member Level: Gold   Points : 3

Hi,

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.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: