Saturday, February 20, 2010

Caching

Caching is a technique widely used to increase performance of the application by keeping the frequently accessed web pages/data in memory.
There are three kinds of caching that can be used by Web applications:
* Output caching
* Fragment caching
* Data caching

Output Caching: increases request/response throughput by caching the content generated from dynamic pages. Every time a page is requested, the subsequent request for that particular page is satisfied by the cache.It is useful where you have static pages.
Syntax :<%@OutputCache Duration="60" VaryByParam="none" %>
@OuputCache is a page directive
Duration parameter specifies how long the HTML output of the Web page should be held in the cache. With the expiration of the duration the cache also become invalid and the ASP.NET Web page then gets generated dynamically, and the cache again gets created with this HTML.
The VaryByParam parameter can be used to cache different views of a dynamic page whose content is generated by GET or POST values.
This type of caching is also known as page level caching.

Fregment Caching: which is also known as partial page level caching allows to cache specific regions of page. Specific regions of your page can be cached with a user control and then @OutputCache directive can be used to cache.The content inside the User Control will be cached for the specified period while the ASP.NET Web page that contains the User Control will continue to serve as a dynamic content.

Data Caching: which is an in-memory cache used for caching objects.The cache is scoped to an application and its lifetime is equivalent to the lifetime of the application.

Caching gives an overall impact on performance of web application.

No comments: