ASP.NET supports two important forms of caching: Page (including sub-page) caching, and Data caching.
Page caching allows the server to store a copy of the output of a dynamic page, and to use this to respond to requests instead of running the dynamic code again. Sub-page caching does the same thing, but for parts of pages.
Data caching allows a web application to store commonly used objects so that they are available for use across all pages in the site. While it was possible to do this kind of thing in ASP, using the Application object, it’s a whole lot better in ASP.NET.
Page Caching :
Two types of page caching is there
a) Page Fragment Caching OR Partial Page Caching
b) Page Output Caching
Page Output Caching:
When we say that the output of a web page is cached, we imply that the web page output is stored in the cache memory. Whenever a new page request is made, the ASP.NET Cache Engine is activated. It checks whether there is a corresponding cache entry for this page. If one is found, it is known as a Cache hit, else, we say that a cache miss has occurred. If there is a cache hit, i.e., if the ASP.NET Cache engine finds a corresponding cache entry for this page, the page is rendered from the cache, otherwise, the page being requested is rendered dynamically.
Page Output caching can be specified in any of the two ways
1. By declaration
<%@ OutputCache Duration="no of seconds"
Location="Any | Client | Downstream | Server | None"
VaryByControl="control"
VaryByCustom="browser |customstring"
VaryByHeader="headers"
VaryByParam="parameter" %>
Where the Cached Data Stored?
when some makes a request from a website there are two types of cache that may satisfy the request without reaching the original server.
The first is the personal cache maintained by the user’s web browser (a ‘browser cache’).
The second is a shared cache present on the network between the user’s browser and the origin server (a ‘proxy cache’).
The page output cache maintained by ASP.NET on the web server is a further type of cache, but when you specify page caching - by setting the Location parameter - you can also make use of these first two sorts of caches.
The values of the OutputCacheLocation is given below.
| Any [default] | The page can be cached on any of: the browser; the proxy server; the web server. |
| Client | The page is to be cached on the browser. |
| Client | The page can be cached on the browser or a proxy server. |
| None | The page is not to be cached. |
| Server | The page is to be cached on the web server. |
| ServerAndClient | The page can be cached on the browser or on the server. |
when caching occurs elsewhere rather than on the server, treate manipulation of the HTTP 1.1 headers that deal with caching.
reference for details :‘Standard Caching over the Internet’ .
Cache Duration :
Pages remain in the cache for some length of time, determined by the Duration parameter. The value is set in seconds.
As we shall see later, if the page caching is set programmatically, rather than declaratively, one can also set a ‘Sliding Expiration’ value which increases the cache duration every time a page is requested.
OR
2. By Program
Response.Cache.SetCacheability (HttpCacheability.Server);
It is also possible to set the OutputCache on all the pages in an ASP.NET application programmatically in the Global.asax page. Refer to the code snippet that follows:--
void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Server);
}
Page Fragment Caching :
It allows specific portions of the web page to be cached rather than caching the entire web page and is useful in situations where a particular web page can contain both static and dynamic content.
Data Caching :
will be comming soon

2 comments:
I would say Caching is a great tool. It really boosts your application performance. But ASP.NET Cache has its limits and if you really want a high performance caching with the ability to scale your applications then NCache is the answer. NCache is a ASP.NET Distributed Cache which features a very effective set of topologies. It also has a free version called NCache Express.
Cheers
Thanks for your valuable comment..
Post a Comment