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.
