Take a label and a Button1 and write following code under button
protected void Button1_Click(object sender, EventArgs e)
{//button
Label1.Text = DateTime.Now.ToLongTimeString();
}
Execution: for every time u click u will see current time as output
In “OutputCache” directive
VaryByParam NONE
The time will not changes by clicking on button for any no. of time ie. The
time is cache in memory and after 1min click on the button you will see the
change in time.(it removes the previous cache and stores new time in cache)
If u copy the url and open it in another browser u will get same result becoz
cache is common to all.
i.e VaryByParam=<value>
the value may be form textbox or any other controls or form varibles.
execute it:
We go for following method to over come the disadv. Of output caching that is DataCaching:
dataset
Linq to xml
Drag and drop a lable(to provide info form where the data is coming form ie
form datasource(product.xml) or form cache),
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Cache["dsproducts"] == null)//cache variable dsproducts if not
existing and check the condition is null or not
{
ds = new DataSet();
ds.ReadXml(MapPath("product.xml"));//mappath to readxml file ie
product.xml
Cache["dsproduct"]=ds;//dataset ds values are stored in dsproduct
Label1.Text = "data from datasource";
}
else
{
ds = (DataSet)Cache["dsproduct"];
Label1.Text="data from cache";
}
GridView1.DataSource=ds;
GridView1.DataBind();
}
}
}