Reputation: 937
I have an action whose output is cached for 20 secs. If i add Action filters(OnActionExecuting & OnActionExecuted) for this action will it be called even if the cached view is taken or will it be called only once in 20secs when the view needs to be created again.
[OutputCache(Duration = 20, Location = OutputCacheLocation.Server, VaryByParam = "")]
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View();
}
Upvotes: 0
Views: 174
Reputation: 8588
When response is served from cache, action filters will be skipped as well. So they will execute just once per 20 seconds.
Upvotes: 1
Reputation: 79461
The meaning of OutputCache
here is that the Index
action will be called at most every 20 seconds. If a thousand requests come in rapid succession, only the first request will actually enter your action and generate the result - the rest will simply lookup the result from the cache (assuming there was enough space in the cache for the result).
The VaryByParam
property of OutputCache
doesn't apply here because your Index
action has no parameters.
Upvotes: 2