Why is OutputCache a result filter and not an action filter in ASP.NET MVC? -


the outputcache attribute commonly given example of result filter in asp.net mvc. this msdn page 1 place. such wraps execution of actionresult object. isn't object executed @ end of action method? i'm confused how allows cached response used , prevents action executing if wraps execution of actionresult @ end of method. know caching works, there obvious piece i'm missing.

the outputcacheattribute inherits actionfilterattribute, in turn implements iactionfilter, , iresultfilter. outputcacheattribute both action filter , results filter.

when think it, makes perfect sense. logic behind cache goes this:

  1. on execution
    • is item in cache?
    • if yes : return cache (done)
    • if no, continue
  2. get result
  3. on exiting
    • put in cache
    • return result

so part 1 handled implementation of iactionfilter, if doesn't return result, continue action , implementation of iresultsfilter handles adding result cache future calls.

thanks asp.net being open source, can confirmed in code. check out outputcacheattribute.cs on codeplex.

  • line 222 cahce checked during onactionexecuting (part of iactionfilter)

  • line 237 - 249 onactionexecuting method sets callback gets invoked during onresultexecuted (part of iresultfilter)


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -