【问题标题】:Clear partial output caching清除部分输出缓存
【发布时间】:2011-12-29 06:26:14
【问题描述】:

我有一个页面,其中包含作为输出缓存(部分输出缓存)的控件。这些设置如下:

[PartialCaching(86400, null, null, "campaign.whatwhere", true)]
public partial class controls_LatestEnquiriesListCached : System.Web.UI.UserControl
{

...

public override string GetVaryByCustomString(HttpContext context, string custom)
{
    if (custom == "campaign.whatwhere")
    {
        return (CampaignManager.CurrentCampaign.DefaultWorkTypeId ?? 0).ToString() + (CampaignManager.CurrentCampaign.DefaultEnquiryAreaId ?? 0).ToString();
    }
    return base.GetVaryByCustomString(context, custom);
}

Global.asax

如何设置才能清除特定页面上的此输出缓存?

是否可以像MyPageWithCachedControl.aspx?ClearCache=true一样设置???

【问题讨论】:

标签: c# asp.net global-asax fragment-caching


【解决方案1】:

您可以创建一个除了清除缓存之外什么都不做的 aspx 页面。您可以获取查询字符串参数并通过缓存键将其删除。

或者您可以尝试查找和 ASP.NET 缓存管理器。

【讨论】:

    【解决方案2】:

    您应该使用HttpResponse.RemoveOutputCacheItem(path) 清除输出缓存,其中path 是https://stackoverflow.com/a/37167/30594 中指定的用户控件的虚拟绝对路径

    【讨论】:

      【解决方案3】:

      使用HTTPResponse.RemoveOutputCacheItem(pathofpage) 清除特定页面的缓存。

      例如:

      private void Button1_Click(object sender, System.EventArgs e)
      {
         HttpResponse.RemoveOutputCacheItem("/form1.aspx");
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-16
        • 2013-01-05
        • 1970-01-01
        相关资源
        最近更新 更多