I use the below code for caching
public class HomeController : Controller
{
[OutputCache(Location=OutputCacheLocation.Server, Duration = 1000, VaryByParam = "id")]
public ActionResult Index(string id)
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
//and trying to invalidate cache in here
Response.RemoveOutputCacheItem(Request.Url.PathAndQuery);
}
}
I try to invalidate the cache by overriding OnActionExecuting method but that method just called first time. So where do I have to try to call Response.RemoveOutputCacheItem()
method to invalidate the cache ?