asp.net页面缓存学习
一个小练习,学习缓存,在页面建一个按键,打印出当前时间,
在页面加上
<%@ OutputCache Duration="15" VaryByParam ="none" %>这行代码,
Duration是注明缓存页面的时间,15秒,VarByParam="none",这行代码的意思是,缓存不加任何条件,这样页面,在15秒内就不会再提交了!
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm8.aspx.cs" Inherits="WebApplication1.WebForm8" %> <%@ OutputCache Duration="15" VaryByParam ="none" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </div> </form> </body> </html>
后台代码
public partial class WebForm8 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { DateTime datetime = DateTime.Now; Label1.Text = datetime.ToString(); } }
缓存今天就学到这里,有时间再学吧