我使用以下代码进行缓存
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);
}
}
我尝试通过重写OnActionExecuting方法使缓存无效,但该方法刚刚第一次调用。那么在哪里我必须尝试调用Response.RemoveOutputCacheItem()
方法来使缓存无效?