<%@ OutputCache Duration="10" varyByParam="none" %>
Response.Write(DateTime.Now.ToString());
//==========================================================
if (!this.IsPostBack)
{
Response.Cache.SetExpires(DateTime.Now.AddSeconds(10));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);
}
TimeMsg.Text = DateTime.Now.ToString("G");//8/29/2007 2:40:07 PM
//==========================================================
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="test" duration="10" varyByParam="None"/>
<add name="test1" duration="5" varyByParam="None"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
<%@ OutputCache CacheProfile="test1" %>
//==========================================================
<%@ OutputCache Duration="60" varyByParam="city" %>
<tr>
<td>
<a href="varyByParam.aspx?city=SZ">SuZhou</a></td>
<td>
<a href="varyByParam.aspx?city=SH">ShangHai</a></td>
<td>
<a href="varyByParam.aspx?city=KS">KunShan</a></td>
</tr>
//==========================================================
//This page uses post cache substitution to insert a dynamic value into a cached page.
<%@ OutputCache Duration="20" varyByParam = "none" %>
Time:
<%= DateTime.Now.ToString() %>
Real Time:
<% Response.WriteSubstitution(new HttpResponseSubstitutionCallback(GetCurrentDate)); %>
public static string GetCurrentDate(HttpContext context)
{
return DateTime.Now.ToString();
}
//==========================================================
//This page uses post cache substitution to insert a dynamic value into a cached page.
<%@ OutputCache Duration="20" varyByParam="none" %>
Time:
<%= DateTime.Now.ToString() %>
Real Time:
<asp:Substitution ID="Substitution1" runat="server" MethodName="GetCurrentDate" />
//==========================================================
//Using the Cache key Dependency
string fileDependencyPath = Server.MapPath("TextFile1.txt");
Cache.Insert("time", DateTime.Now, new CacheDependency(fileDependencyPath));
Response.AddCacheItemDependency("time");
// Set additional properties to enable caching.
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);
TimeMsg.Text = DateTime.Now.ToString("G");
//==========================================================
//Using the File Dependency
if (!this.IsPostBack)
{
string fileDependencyPath = Server.MapPath("TextFile1.txt");
Response.AddFileDependency(fileDependencyPath);
// Set additional properties to enable caching.
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);
}
TimeMsg.Text = DateTime.Now.ToString("G");
//==========================================================
//Cache Control
<%@ OutputCache Duration=30 varyByControl="TextBox1" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
protected void Button1_Click(object sender, EventArgs e)
{
this.Response.Write(DateTime.Now.ToString());
}
//==========================================================
//Cahce webusercontrol
//最终是根据Page设置的过期时间,本例即为10s
Page:
<%@ OutputCache Duration=10 varyByParam="None" %>
<uc1:webusercontrol ID="webusercontrol1" runat="server" />
webusercontrol.ascx:
<%@ OutputCache Duration=5 varyByParam="None" %>
Response.Write(DateTime.Now.ToString());
http://www.cnblogs.com/PLAYBOY840616/archive/2007/08/29/874624.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。