Is there a way to disable the outputcache here programmatically if something happens that is not an exception?
[OutputCache(CacheProfile = "StatisticSheets")]
public virtual ActionResult GameStatistics(int? eventId, int? divisionId, string ids)
{
If(true) {
// Don't Cache This Page
}
return View();
}
2
Answers
This is how i have done:
create a derive class from outputcache:
then in controller:
hope it helps.
If you need global to disable then read the below details, at the end also I shared with action method implementation code.
First, we want to capture whether or not the app is in debugging mode when it is launched. We’ll store that in a global variable to keep things speedy.
Then in the Global.asax code’s Application_Start method, write to the global property.
Now we will create our own class to use for caching, which will inherit from
OutputCacheAttribute
.Now when you decorate your controller endpoints for caching, simply use your new attribute instead of
[OutputCache]
.With Action Method
-> For .net Framework:
[OutputCache(NoStore = true, Duration = 0)]
-> For .net Core:
[ResponseCache(NoStore = true, Duration = 0)]
You can use the particular action method above way