I'm using donut output caching on a certain action, which uses this action filter:
public sealed class DoStuffAttribute : ActionFilterAttribute {
private bool HasRun = false;
public override void OnActionExecuting(ActionExecutingContext context) {
HasRun = true;
}
public override void OnActionExecuted(ActionExecutingContext context) {
HasRun = true;
}
public override void OnResultExecuting(ResultExecutingContext context) {
if (HasRun) doSomething();
}
public override void OnResultExecuted(ResultExecutedContext context) {
if (HasRun) doSomething();
}
}
For the first request, HasRun
is set, and then the action's results are cached.
For following requests, OnActionExecuting
and OnActionExecuted
are not run, as the action is cached. BUT, in the OnResultExecuting
and OnResultExecuted
methods, which do run, the HasRun
flag is true!
Does OutputCache cache not only the result, but also the state of action filters? If not, what is happening here?