It is used to maintain the result of the webform temporarily such that if any furthur requests from the client are received then the server inspite of processing every request provides the temporarily stored ie.. cached content as a response.
ASP.NET 4.0 suports 2 types of caching:
If the cached content is maintained at the client system then it is said to be ClientSide caching.
Ø ASP.Net implicitly sets the clientSide cache.
Ø InOrder to clear the clientside cache then set “Response.Expires=-1” .
If the cached content is maintained on the server system then it is said to be a serverside cache.
ASP.net supports following types of serverside caching methods.
a) Page Output Cache:
It is used to maintain the entire result or output of the webform for a temporary period of time at server such that the same cached content will be provided as responsr for every client request.
How to set ?
In the .aspx file of any application say for example
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="AllUsers.aspx.cs" Inherits="AllUsers" %>
After the above lines of code add the following code
<%@ OutputCache Duration="seconds" VaryByParam="control|variable|none" %>
Ex: <%@ OutputCache Duration="600" VaryByParam="none" %>
If this attribute is set with a control or a variable name then every unique value assigned for this , an individual cache page will be created and will be maintained at the server such that the relevant cache page will be responded based on the parameters.
Instead of maintaining th complete webform content as a cache only aparticular part of the webform will be cached which is also known as “partial page caching”.
Inorder to achieve this method a WebUserControl with the contents to be maintained as cache should be defined.
It is used to create reusable components such that the control can be used in any webform present within the websites.
Ø Set the output cache for the webuser control.
Ø Add the webform and design the webform according to the requirement.
Ø Use the webusercontrol as server control within the webform.
c) Substitution Caching:
InOrder to achieve this “substitution control” should be used.This control is used to provide dynamic content.
In the properties of substitution vontrol “Method “ should be added.
The method binded with the substitution control should be a “Public StAtic Method” And the method should accept “http context"