在哪里调用HttpResponse.RemoveOutputCacheItem()?

时间:2011-10-02 17:01:41

标签: .net asp.net-mvc asp.net-mvc-3 caching outputcache

我使用以下代码进行缓存

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()方法来使缓存无效?

0 个答案:

没有答案