Clear partial output caching

1.3k Views Asked by At

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

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???

3

There are 3 best solutions below

0
On

You should use HttpResponse.RemoveOutputCacheItem(path) to clear the output cache where path is the virtual absolute path of the user control as specified in the https://stackoverflow.com/a/37167/30594

0
On

You can create an aspx page that does nothing but clears cache. You can take the querystring parameter and have it delete by cache key.

Or you can try to find and ASP.NET cache manager.

0
On

Use HTTPResponse.RemoveOutputCacheItem(pathofpage) to clear the cache of a particular page.

For example:

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