简体   繁体   English

清除部分输出缓存

[英]Clear partial output caching

I have a page that has controls that are output caches (partial output caching). 我有一个页面,其控件是输出缓存(部分输出缓存)。 These are setup like this: 这些设置如下:

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

...

With

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);
}

In Global.asax Global.asax

How can I setup so I can clear this output cache on a specific page? 如何设置以便我可以在特定页面上清除此输出缓存?

Is it possible to setup like MyPageWithCachedControl.aspx?ClearCache=true ??? 是否可以设置像MyPageWithCachedControl.aspx?ClearCache=true ???

Use HTTPResponse.RemoveOutputCacheItem(pathofpage) to clear the cache of a particular page. 使用HTTPResponse.RemoveOutputCacheItem(pathofpage)清除特定页面的缓存。

For example: 例如:

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

You can create an aspx page that does nothing but clears cache. 您可以创建一个除了清除缓存之外什么都不做的aspx页面。 You can take the querystring parameter and have it delete by cache key. 您可以使用querystring参数并按缓存键删除它。

Or you can try to find and ASP.NET cache manager. 或者您可以尝试查找和ASP.NET缓存管理器。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM