3

I have a question about caching in ASP.NET MVC 5. I have an action that decorates with OutputCacheAttribute. something like this: OutputCache(Duration = 900, Location = Server, VaryByParam = "id")

somewhere in my application I want to manage caches and remove them. I used Response.RemoveOutputCacheItem(Url.Action("Index", "Home")) to remove all caches of an action, but it doesn't work.

The HttpResponse.RemoveOutputCacheItem() method was worked on actions with parameters but I want to clear all outputcaches of the action without parameters.

for example:

Controller:

    [OutputCache(Duration = 900, VaryByParam = "*")]
    public ActionResult About(int id)
    {
        return View();
    }

Routing:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

Remove by below code:

var x = Url.Action("About", "Home");
Response.RemoveOutputCacheItem(x);
Mojtaba Rezaie
  • 98
  • 1
  • 10
  • 1
    @NitinVarpe that is a useful looking output caching extension, but how does it answer the OP's query about removing output cached for a specified controller? – Matt Evans Jan 04 '16 at 13:02
  • 1
    There's not enought detail in your post to say, but possibly this answer is useful : http://stackoverflow.com/questions/8968508/httpresponse-removeoutputcacheitem-is-not-working – Matt Evans Jan 04 '16 at 13:04
  • You are right @MatthewEvans! – Nitin Varpe Jan 05 '16 at 05:02

0 Answers0