Following are main advantages of using cookies in web application:
- It's very simple to use and implement.
- We can avoid database hitting.
- We can reduce network traffic.
Cache["Employee"] = "DataSet Name"
We can create data caching use Cache Keyword. It's located in the System.Web.Caching namespace. It's just like assigning value to the variable
How to Read data from Data Cache?
Dataset dsEmployee = (Dataset) Cache ["Employee"]
This is very similar to assigning object to the Dataset.
Where does Data Cache are stored?
This is one of the interesting things to find out the Data Caching in your local drive. First of all, From "IE Internet Option ", delete Browsing History to clear Cache.
We can remove Data Cache manually.
//We need to specify the cache name
Cache.Remove(String key);
Example:
TimeSpan ts =
new TimeSpan(0, 0, 10);
//If cache has null, it will create two cache
and it will bind into the gridview
if (Cache["Employee"] == null)
{
dtEmployee = new DataTable("Employee");
dtEmployee.Columns.Add("EmpID", typeof(int));
dtEmployee.Columns.Add("EmpName", typeof(string));
DataRow rs = dtEmployee.NewRow();
rs[0] = 10;
rs[1] = "Annathurai";
dtEmployee.Rows.Add(rs);
//To assign datatable to cache memory.
Cache["Employee"] = dtEmployee;
Cache.Insert("Employee", dtEmployee, null, Cache.NoAbsoluteExpiration, ts);
Response.Write("Its processing with Database hit");
}
else
{
//If cache has value, It retrive from cache memory and bind into the gridview
Response.Write("Its processing from cache");
}
/Here we are converting cache into datatable
GridView1.DataSource = (DataTable)Cache["Employee"];
GridView1.DataBind();
Summary
There are many topics to learn with Data Caching. I have covered a small portion hope this will helps all the beginners to startup. Please give your feedback and suggestion.
History
- Written on 01-March-2010, Monday

Nayak AnshumanPosted Jul 12, 2019, 5:04 PM EDT
Thank you so much...but please give some article on Page and Fragment cache ,cookie..
Dorababu ManyamPosted May 2, 2018, 2:53 AM EDT
Great work..explained in simple terms.. keep it up
Qais BuberePosted Dec 5, 2017, 8:42 PM EST
I am not able to create cache. " Cache is a type which is not valid in the given context". this is my error ..please help
Ashok VadlamaniPosted Oct 16, 2017, 10:29 PM EDT
Good article explained neatly in simple terms
Deepak AgarwalPosted Jun 6, 2016, 12:05 AM EDT
Great work.. But even i want to know that this cache concept work on digital signage player. bcoz i am trying to making digital signage player... so i need to somebody help..
Amatya AgyeyPosted Apr 5, 2016, 10:08 PM EDT
Nice article sweet and simple to understand for freshers.
ayuf rahmanPosted Nov 10, 2015, 4:00 AM EST
good
Rajat ChananPosted Jun 20, 2014, 1:01 AM EDT
nice description in short.
sagar BhosalePosted Jan 31, 2011, 8:04 PM EST
Thanks for uploading such nice tutorials. I want to know how to create Chatting application in browser? using simple asp.net concept without using socket & remoting concept.Please replye as you possible.