moonpyk / mvcdonutcaching

ASP.NET MVC Extensible Donut Caching brings donut caching to ASP.NET MVC 3 and later. The code allows you to cache all of your page apart from one or more Html.Actions which can be executed every request. Perfect for user specific content.
https://github.com/moonpyk/mvcdonutcaching
MIT License
142 stars 50 forks source link

Is it safe to use OnResultExecuting and OnResultExecuted however I want? #47

Closed migig closed 9 years ago

migig commented 9 years ago

An actionfilter has four hooks: OnActionExecuting, OnActionExecuted, OnResultExecuting, OnResultExecuted. I understand that this library uses the first two.

I need to use other actionfilters on my cached action. I usually use OnActionExecuting, but the action is cached so such an actionfilter won't be called. So instead I put such code in a donut hole (i.e. child view) and call it from a view. This works but is "messy" and harder to test.

So I've been trying to put this kind of stuff into actionfilters which use OnResultExecuting and OnResultExecuted. I noticed that it works most of the time as I expect.

What I need to know is this "safe" or will I break something? Can I do whatever I want in these two functions? Including changing headers, setting cookies, redirecting, etc.? I assume the only thing I can't do is change the cached result, but everything else is ok?

migig commented 9 years ago

I discovered this which answers the question. The info was buried in the comments in the blog, so I didn't see them. Bottom line, unlike normal output caching, this library allows you to place the code in any of the four methods. Just ensure the filter ordering is right.