Reputation: 25986
I am trying to cache some of my expensive to generate charts. So I did this in Web.config
:
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<!-- 4 hours : 60 sec x 60 min x 4 hour = 14400 sec -->
<add name="ChartCacheProfile" duration="14400" varyByParam="none" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
And I added this in my Controller
:
[OutputCache(CacheProfile="ChartCacheProfile")]
public ActionResult GenerateChart()
But this does not work..., the result is still not cached and the Action
is being executed always. This can take up to 1 minutes to complete.
Please note that the url being called with different parameter every time. The parameter is unrelated to the chart being generated. That is why I put varyByParam="none"
.
Upvotes: 7
Views: 1732
Reputation: 1011
I've got tired of this issue and having to set varyByParam for each action. So here's simple code for output cache attribute that gets varyByParam from web.config. https://github.com/unconnected4/MvcOutputCacheFix/blob/master/ParameterizedOutputCacheAttribute.cs
Upvotes: 2
Reputation: 49095
I suspect it is a bug indeed. What worked for me is to set VaryByParam
explicitly in the OutputCache
attribute:
[OutputCache(CacheProfile="ChartCacheProfile", VaryByParam="None")]
public ActionResult GenerateChart()
Upvotes: 8