I want an easy way to clear cached pages on my asp.net-mvc website.
I have expensive DB operations so i often use outputcaching to make the site run faster. I have code that looks like this:
[OutputCache(Duration = 30000)]
public ActionResult Index()
{
return View();
}
[OutputCache(Duration = 30000, VaryByParam = "*")]
public ActionResult GetData(MyParams myParams)
{
return PartialView("MyView", GetVM(myParams));
}
There are certain times (when things go wrong) when i want to explicitally clear this cache (regardless of the existing Cache duration)
is there anyway for full and partial page Outputcaching to remove the cached page and run through the full code ?
NOTE: I see that this question is asked already in general around asp.net like here but i dont see an asp.net-mvc specific solution
i have tried this but it doesn't seem to work:
public ActionResult ClearCache()
{
this.HttpContext.Response.RemoveOutputCacheItem("/MyController/Index.aspx");
this.HttpContext.Response.RemoveOutputCacheItem("/MyController/MyView.开发者_开发问答ascx");
}
For a MVC based solution you can do something like this
this.HttpContext.Response.RemoveOutputCacheItem(Url.Action("MyAction","MyController",new{ id = 1234}));
精彩评论