I'm using MvcDonutCaching on my project and looking for a way to disable caching globally to assist during debugging/testing.
I can't find any examples on how to achieve this in the documentation though I did find the CacheSettingsManager
which exposes a IsCachingEnabledGlobally
property however this is readonly
.
The CacheSettingsManager
doesn't have any constructors which would allow me to configure this setting either. Is there a way of configuring this setting?
There is an alternative solution which may work (ugly) but it's an absolute last resort and shouldn't really be necessary:
public class CustomOutputCache : DonutOutputCacheAttribute
{
public CustomOutputCache()
{
if(ConfigurationManager.AppSettings["UseCache"] == "false")
{
base.NoStore = true;
base.Duration = 0;
}
}
}
And then using this on my controller actions:
[CustomOutputCache]
public ActionResult Homepage()
{
// etc...
}
Is there a correct way to do this?
It is an ugly solution, but you could consider the use of compilation flags. Something like:
This will compile the attribute only when non-Debug configurations are selected.