subclassing outputcache issues in mvc3


I am having some issues understanding what is happening when I create a simple subclass of OutputCacheAttribute in MVC3. Here is the code:

public class ExampleOutputCacheAttribute : OutputCacheAttribute { public ExampleOutputCacheAttribute() { // breakpoint here } public override void OnActionExecuting(ActionExecutingContext filterContext) { // breakpoint here base.OnActionExecuting(filterContext); } public override void OnActionExecuted(ActionExecutedContext filterContext) { // breakpoint here base.OnActionExecuted(filterContext); } public override void OnResultExecuting(ResultExecutingContext filterContext) { // breakpoint here base.OnResultExecuting(filterContext); } public override void OnResultExecuted(ResultExecutedContext filterContext) { // breakpoint here base.OnResultExecuted(filterContext); } }

The first time a controller action with this attribute is requested, the constructor and all overridden methods are hit, but if I refresh the page, none of the methods or the constructor are hit. It is as if the cache is being read from outside the OutputCacheAttribute, but looking at the MVC source code for OutputCacheAttribute, I can see that in OnActionExecuting, there is code for checking for a cached page and returning the result:

filterContext.Result = new ContentResult() { Content = cachedValue };

Can anyone shed any light on what is happening?


It seems as though the OutputCache filter is more complicated than it originally appears. For page caching, it hooks in to the standard ASP.NET output caching mechanism which uses the OutputCacheModule HttpModule in IIS. Once the filter is hit once and adds the page to the cache, subsequent requests do not hit the filter in any way. The OutputCacheModule intercepts these requests and returns the cached object higher up the pipeline.

For action caching, a separate mechanism is used. This uses a static MemoryCache and the constructor and all overridden methods are hit on every request.


  • How to create an actor in a clustered configuration in F#
  • Force iPad app to launch in portrait when landscape is supported
  • Open Graph Publish Using Spring Social
  • Play 2.0.4 file upload. NullPointerException: null
  • How do I create a new row inside an angular ng-repeat?
  • I have a modal that opens a second modal and cannot close the first modal if open then close the sec
  • Multiple storyboards: should I use a singleton pattern to cache them?
  • Requiring gem in Rails 3 Controller failing with “Constant Missing”
  • Single virtual attribute definition for multiple fields
  • Mod rewrite redirection to another domain if file not exist
  • Sending rails errors to rspec output
  • Rails XML builder not rendering
  • p:fileDownload in p:dataTable does not work (just refreshes page) after performing search on the p:d
  • keeping track of nested ng-repeat index's
  • Change attribute of custom directive
  • Mvc 3 posting content type application/json, action method arguments loose mapping?
  • Receiver has no segue with identifier“***”
  • Angular Bootstrap Carousel Slide Transition not working correctly
  • Can you pass an array from javascript to asp.net mvc controller action without using a form?
  • redirect_to root_url and return unless @user.activated
  • Getting the scrolling offset when storing coordinates
  • Bootstrap (v3.3.4) glyphicons not displayed in IE when refresh page (F5)
  • Creating a DropDownList
  • ThreadStatic in asynchronous ASP.NET Web API
  • Implementing “partial void” in VB
  • ASP.NET MVC Application won't update some controllers
  • Sending HTML Form Data to Spring REST Web Service
  • CakePHP ACL tutorial initDB function warnings
  • Sencha Touch 2.0 Controller refs attribute not working?
  • Get one-time binding to work for ng-if
  • Fetching methods from BroadcastReceiver to update UI
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Does CUDA 5 support STL or THRUST inside the device code?
  • what is the difference between the asp.net mvc application and asp.net web application
  • bootstrap to use multiple ng-app
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Binding checkboxes to object values in AngularJs
  • How to load view controller without button in storyboard?