ASP.NET caching stores frequently accessed data or whole webpages in memory, where they can
be retrieved faster than they could be from a file or database. This helps to improve the performance
and increase the scalability (in terms of number of users serviced) of a web application.
As an example, if you have a product catalog in an e-commerce application, you might consider
putting a lot of the catalog data into cache. Data that changes infrequently and is accessed by
a lot of users is a good candidate for caching. The first access of this data would load it into the
cache; subsequent requests would be served from the cache until the cache expires.
Simple way to use catching is given below :
<%@ Page Language="C#" %> <%@ OutputCache Duration="60" VaryByParam="None" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, System.EventArgs e) { Label2.Text = "Present Time: "; Label2.Text += DateTime.Now.ToString(); } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>asp.net caching example: how to use output caching</title> </head> <body> <form id="form1" runat="server"> <div> <h2 style="color:Red">asp.net example: Output Caching</h2> <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="SeaGreen" Text="Output Caching Duration: 60 seconds." > </asp:Label> <br /><br /> <asp:Label ID="Label2" runat="server" Font-Size="Large" ForeColor="DodgerBlue" > </asp:Label> </div> </form> </body> </html>
OUTPUT



No comments:
Post a Comment