| Author: Shivshanker Cheral 03 Jul 2008 | Member Level: Diamond | Rating:  Points: 6 |
While functionality is the number one goal of Web development, performance seems to be a close second. After all, a site that isn't used serves no purpose. Caching frequently accessed Web page data is one way to positively impact a Web application's performance. ASP.NET includes caching support that is easily incorporated in your application to boost application performance. ASP.NET 1.x provides three ways to incorporate caching in a Web application:
Page Output caching: allows you to cache the dynamically generated page content.
Page Fragment caching: caches portions of a Web page.
Page Data caching: programmatically caches data/objects within a Web page.
In this article, I will focus my attention on Page Output caching. Page Output caching Output caching is applicable when the contents of an entire page are relatively static so it may be cached. Caching frequently accessed pages can result in substantial throughput gains. The way it works is initial page requests are generated dynamically with all subsequent requests served from the cache. The result is an enormous performance gain with heavily used applications.
The main aspect of caching a page is the expiration date. It determines how long content will be retained in the cache before it is reloaded from the source. It is accessible via code or with the page-level OutputCache directive. It includes the Duration parameter for specifying how long an item will be cached (in seconds). Along with Duration, the OutputCache directive contains the following attributes:
Location : The location of the cache. Valid values include Any, Client, Downstream, None, Server, and ServerAndClient. The default value is Any.
CacheProfile : The name of the cache settings to associate with the page. It is an optional element with no default value.
NoStore : A Boolean value signaling whether to prevent secondary storage of sensitive data.
Shared : A Boolean value that determines whether user control output can be shared with multiple pages.
VaryByCustom : Any text that represents custom output caching requirements.
VaryByHeader : A semicolon-separated list of HTTP headers used to vary the output cache.
VaryByParam : A semicolon-separated list of strings used to vary the output cache.
The key elements used most frequently are Duration and VaryByParam, which allows you to create different page level caches based on parameters. These parameters correspond to querystring values sent with HTTP GET requests or form parameters sent along with HTTP POST requests. When this attribute is set to multiple parameters, the output cache contains a different version of the requested document for each combination of specified parameters. Possible values include none, an asterisk (*), and any valid query string or POST parameter name.
Listing A contains a basic approach to page level caching with a C# page that loads employee data from the venerable SQL Server Northwind database. The data is relatively static, so it is cached for five minutes. Listing B contains the equivalent VB.NET code.
Listing A <%@ OutputCache Duration="300" VaryByParam="none" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Page language="c#" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html><head><title>Employees</title>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e) {
if (!this.IsPostBack) {
String cString = "Data Source=test;Initial Catalog=Northwind;User Id=sa;Password=;"; SqlConnectionconn = null; SqlCommandcomm = null; SqlDataAdaptersda = null; DataSetds = new DataSet(); conn = new SqlConnection(cString); comm = new SqlCommand("SELECT EmployeeID, LastName, FirstName, City, HomePhone, Title FROM dbo.Employees ORDER BY LastName", conn); sda = new SqlDataAdapter(comm); sda.Fill(ds); dgCache.DataSource = ds; dgCache.DataBind();
} }
</script></head>
<body>
<form id="frmTechRepublicCaching" method="post" runat="server">
<asp:DataGrid id="dgCache" AutoGenerateColumns="False" runat="server" Width="525px" Height="281px">
<Columns>
<asp:BoundColumnDataField="EmployeeID" Visible="False" />
<asp:BoundColumnDataField="LastName" HeaderText="Last" />
<asp:BoundColumnDataField="FirstName" HeaderText="First" />
<asp:BoundColumnDataField="Title" HeaderText="Title" />
<asp:BoundColumnDataField="City" HeaderText="City" />
<asp:BoundColumnDataField="HomePhone" HeaderText="Phone" />
</Columns>
</asp:DataGrid>
</form></body></html>
Listing B <%@ OutputCache Duration="60" VaryByParam="none" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Page language="vb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html><head><title>Employees</title>
<script language="vb" runat="server">
Sub Page_Load()
If Not (IsPostBack) Then
Dim cString As String cString = "Data Source=test;Initial Catalog=Northwind; User Id=sa;Password=;"
Dim conn As SqlConnection
Dim comm As SqlCommand
Dim sda As SqlDataAdapter
Dim ds As new DataSet() conn = new SqlConnection(cString) comm = new SqlCommand("SELECT EmployeeID, LastName, FirstName, City, HomePhone, Title FROM dbo.Employees ORDER BY LastName", conn) sda = new SqlDataAdapter(comm) sda.Fill(ds) dgCache.DataSource = ds dgCache.DataBind()
End If
End Sub
</script></head>
<body>
<form id="frmTechRepublicCaching" method="post" runat="server">
<asp:DataGrid id="dgCache" AutoGenerateColumns="False" runat="server" Width="525px" Height="281px">
<Columns>
<asp:BoundColumnDataField="EmployeeID" Visible="False" />
<asp:BoundColumnDataField="LastName" HeaderText="Last" />
<asp:BoundColumnDataField="FirstName" HeaderText="First" />
<asp:BoundColumnDataField="Title" HeaderText="Title" />
<asp:BoundColumnDataField="City" HeaderText="City" />
<asp:BoundColumnDataField="HomePhone" HeaderText="Phone" />
</Columns>
</asp:DataGrid>
</form></body></html>
|
| Author: Tanuja 03 Jul 2008 | Member Level: Gold | Rating:  Points: 3 |
Hi, Refer this link...
http://www.c-sharpcorner.com/UploadFile/vishnuprasad2005/ImplementingCachinginASP.NET11302005072210AM/ImplementingCachinginASP.NET.aspx
|
| Author: Miss Meetu Choudhary 24 Oct 2008 | Member Level: Diamond | Rating:  Points: 6 |
Caching
It refers to information that is reused in your application, or information that is stored on your computer so it can be reused. For example, if you download an image from the internet, it's often cached so you can view it again without downloading the image data. Caching is a form of replication in which information learned during a previous transaction is used to process later transactions.
or in other words we can say
To make web surfing faster, web browsers store recently visited pages on the user’s disk. When the site is revisited, the browser displays pages from the cache instead of requesting them from the server. Reloading brings up the current page from the server.
As related to caching reports, this involves storing the results of pre-run reports in tables (instead of caching to memory as the usage of the word implies) so that when the user accesses the report for the first time, it seems to run instantaneously. This is a feature provided by the server component of many of the popular OLAP tools.
Once a website has been requested it is stored on the networks caching server. Next time a user on that network requests the same website, it can be found on the local cashing server instead of having to travel across the Internet.
summary:--
A cache is a local copy of data available over a network. When for example a web page is requested, the network software retrieves the page, but also saves it locally. When the page is requested again, it will make it available from the cache, thus speeding up the process of viewing the page. This only works for web pages which do not have dynamic data on them or which have not altered recently. The system works better for graphics and other elements of a web page which do not change very often.
== Thanks and Regards Meetu Choudhary
Thanks and Regards Miss Meetu Choudhary (Site Coordinator) Go Green Save Green My Profile on Google
|