How to evict from output cache when using varybycustom for multitenant app?

旧时模样 提交于 2019-12-24 03:06:06

问题


I have an app that runs on Azure Web Worker Roles and is using the Co-Located Role Cache as the default output cache.

I also use a varybycustom so that I can partial cache a page with cachable areas.

So in my home page I have this:

 <div id="collectionsheader">
    @Html.Action("Header", new{ controller = "Collections", area="Dam" })
</div>

which refers to this action:

[OutputCache(Duration = 3600, VaryByCustom = "host")]
    public ActionResult Header()
    {
       ...
    }

the varybycustom is so that in this multitenant app the cached output is changed for each subdomain which accesses the app. This is in the Global.ascx:

public override string GetVaryByCustomString(HttpContext context, string arg)
    {
        if (arg == "host")
        {
            return context.Request.Headers["host"];
        }
    }

So here is the question How do I evict this content per domain when I need to force a refresh of this item.

Currently I am doing this:

var urlToRemove = url.Action("Header", "Collections");
if (urlToRemove != null) HttpResponse.RemoveOutputCacheItem(urlToRemove);

But this is not working, and I am sure it's because of the VaryByCustom key.

Can anyone shed any light on to how I would evict this cached content when I need to?

Thanks in advance.

来源:https://stackoverflow.com/questions/20288600/how-to-evict-from-output-cache-when-using-varybycustom-for-multitenant-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!