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:
- on execution
- is item in cache?
- if yes : return cache (done)
- if no, continue
- get result
- 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 ofiactionfilter
)line 237 - 249
onactionexecuting
method sets callback gets invoked duringonresultexecuted
(part ofiresultfilter
)
Comments
Post a Comment