I have added Output Caching to a couple of actions in my app for some easy performance boosts. However, these actions also need to increment a counter after each request (it's a views counter) by hitting a Redis db.
At first, I figured I could just adjust the order in which the action filters execute to ensure the view is counted:
public class CountersAttribute : ActionFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
//increment my counter all clever like
base.OnResultExecuted(filterContext);
}
}
But that didn't work; apparently the OutputCacheAttribute doesn't behave like a normal action filter. Then I tried implementing a custom output cache:
public class OutputCacheWithCountersAttribute : OutputCacheAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
//straight to the source to get my headcount!
base.OnResultExecuted(filterContext);
}
}
Nope, didn't work either; action filters appear to be entirely ignored once an action is cached. Bummer.
So, uh, is there any way (without implementing a custom output caching provider) for me to ensure my views are counted properly that is clean and sensible?