清除 OutputCache 的方法
时间:2014-07-08 13:20 来源: 我爱IT技术网 作者:山风
如何清 OutputCache那?
清除单页 OutputCache 的方式可使用下列语法
HttpResponse.RemoveOutputCacheItem("/test.aspx");
但如果想要清除所有的 OutputCache,上网找到一个方法,实际测试是可以 WORK 的,以下为sample。
Global.asax
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
HttpContext.Current.Cache.Insert("task-index", DateTime.Now);
}
</script>
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ OutputCache Location="Server" VaryByParam="*" Duration="60" %><form id="form1" runat="server"><asp:label id="lblNow" runat="server"></asp:label></form>
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{Response.AddCacheItemDependency("task-index");lblNow.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");}
ClearOutputCache.aspx
<asp:button id="btnClear" onclick="btnClear_Click" runat="server" text="Clear"></asp:button>
ClearOutputCache.aspx.cs
protected void btnClear_Click(object sender, EventArgs e)
{
HttpContext.Current.Cache.Insert("task-index", DateTime.Now);
}
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
