ASP.NET provides two types of caching
Caching is for providing the solutions or results to the users depending on their requested request. A cache simply stores the output generated by a page in the memory and this saved output (cache) will serve us (users) in the future.
1) output caching
It allows you to store dynamic page and user control responses on any HTTP 1.1 cache-capable device in the
output stream, from the originating server to the requesting browser. On subsequent requests, the page or
user control code is not executed; the cached output is used to satisfy the request.
Page Caching :- To cache an entire page's output we need to specify a directive at the top of our page, this directive is the @ OutputCache.
<%@ OutputCache Duration = 5 VaryByParam = "ID" %>
Here, in that statement Duration and VarByParam are the two attributes of the OutputCache directive.
Fragment caching :- In some scenarios we only need to cache only a segment of a page. For example a contact us page in a main page will be the same for all the users and for that there is no need to cache the entire page. So for that we prefer to use fragment caching option.
<%@ OutputCache Duration = 10 VaryByParam = "None" %>
2) data caching
It can be used to programmatically store arbitrary objects, such as application data, in server memory so that
your application can save the time and resources it takes to recreate them.
As we know in C# everything is about classes and objects. So ASP.NET supports data caching by treating them
as small sets of objects. We can store objects in memory very easily and use them depending on our
functionality and needs, anywhere across the page.
For inserting the cache into the objects, the insert method of the Cache class can be used. This insert method
is used as follows:
Cache.Insert("Website", strName, new CacheDependency(Sever.MapPath("Website.txt")
DateTime.Now.Addminutes(5), TimeSpan.Zero);