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"
.
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()
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With