CSharp OutputCache Directive Example

The OutputCache directive is added to the header of any ASP.NET page. It specifies the duration (in seconds) that the page should be cached. The OutputCache directive example below specifies that this particular page should be cached for one hour after its first access.

<%@ Page Language="C#" %>
<%@ OutputCache Duration='3600' VaryByParam='none' %>
<html>
 
  <script runat="server">
    protected void Page_Load(Object sender, EventArgs e) {
           _genon.Text = DateTime.Now.ToString();
    }
  </script>
 
  <body>
    <h3>Output Cache example</h3>
    <p>Last run on:
       <asp:label id="_genon" runat="server"/></p>
  </body>
 
</html>

Developers must specify at least the Duration and VaryByParam attributes. If the VaryByParam attribute is set to ‘none’ a copy of the page will be cached for each request type (GET, HEAD, or POST) separately.

Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

Filed Under: Language Basics

Tags:

RSSComments (1)

Leave a Reply | Trackback URL

  1. [...] the rest here: CSharp OutputCache Directive Example | Language Basics | w3mentor NSF Grant Proposal ExampleBotanical Gardens » Blog Archive » My Friends Children Have [...]

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.