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; 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"];
rs[1] = "Annathurai";
dtEmployee.Rows.Add(rs);
//To assign datatable to cache memory. 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, 9:04 PM
Thank you so much...but please give some article on Page and Fragment cache ,cookie..
Dorababu ManyamPosted May 2, 2018, 6:53 AM
Great work..explained in simple terms.. keep it up
Qais BuberePosted Dec 6, 2017, 1:42 AM
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 17, 2017, 2:29 AM
Good article explained neatly in simple terms
Deepak AgarwalPosted Jun 6, 2016, 4:05 AM
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 6, 2016, 2:08 AM
Nice article sweet and simple to understand for freshers.
ayuf rahmanPosted Nov 10, 2015, 9:00 AM
good
Rajat ChananPosted Jun 20, 2014, 5:01 AM
nice description in short.
sagar BhosalePosted Feb 1, 2011, 1:04 AM
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.