.net - Asp.Net MVC 3 Partial Page Output Caching Not Honoring Config Settings -
i have simple partial view i'm rendering in main view with:
@html.action("all", "template")
on controller have this:
[outputcache(cacheprofile = "templates")] public actionresult all() { return content("this stinks."); }
and in config this:
<caching> <outputcachesettings> <outputcacheprofiles> <clear/> <add name="templates" duration="3600" varybyparam="none"/> </outputcacheprofiles> </outputcachesettings> <outputcache enableoutputcache="false" enablefragmentcache="false" /> </caching>
this fail @ runtime exception:
error executing child request handler 'system.web.mvc.httphandlerutil+serverexecutehttphandlerasyncwrapper
and inner exception:
duration must positive number
now it's not picking web.config settings, because if change to:
[outputcache(duration = 3600)]
it work, notice in web.config turned off enableoutputcache , enablefragmentcache, doesn't honor these settings.
curiously, in normal view these settings work fine, partial views breaking this? missing something? the gu says should work fine... in short, supposed honor caching settings in web.config , if not, why not?
so took minute , looked @ mvc 3 source. first thing came me feature seemed bit hacky. because reusing attribute works in 1 situation honoring of properties , config settings, , in child action scenario ignoring of settings , allowing varybyparam , duration.
how 1 go figuring out supported beyond me. because exception want throw says unsupported setting never thrown unless supplied duration , varybyparam value
here main piece of code smells:
if (duration <= 0) { throw new invalidoperationexception(mvcresources.outputcacheattribute_invalidduration); } if (string.isnullorwhitespace(varybyparam)) { throw new invalidoperationexception(mvcresources.outputcacheattribute_invalidvarybyparam); } if (!string.isnullorwhitespace(cacheprofile) || !string.isnullorwhitespace(sqldependency) || !string.isnullorwhitespace(varybycontentencoding) || !string.isnullorwhitespace(varybyheader) || _locationwasset || _nostorewasset) { throw new invalidoperationexception(mvcresources.outputcacheattribute_childaction_unsupportedsetting); }
i'm not sure why isn't called out in documentation, if api should make clear, or @ least throw right exception.
in short, partial output caching works, butt not want too. i'll work on fixing code , honoring of settings enabled.
update: fixed current implemenation @ least work situation respecting enabled flag , allowing cache profiles web.config. detailed in blog post.
Comments
Post a Comment