AspNetCore.CacheOutput
AspNetCore.CacheOutput copied to clipboard
Conditionally disable caching
The old behavior was that the caching needed to be explicitly activated by providing the UseCacheOutput method.
Now the caching is implicitly active. It would be nice to activate the caching conditionally. For example I could activate the caching only for the production environment:
if (env.IsProduction())
{
app.UseCacheOutput();
}
Is there a way to deactivate the caching? The only way I can think of is by implementing my own fake IApiCacheOutput which doesn't cache anything.
There are a lot of ways to implement:
- Preprocessor directives (conditional compilation) in every place where CacheOutput attribute is being used (not really convenient as for me).
- Create your own attribute, inherited from existing CacheOutputAttribute, and override IsCachingAllowed method to always return false on condition.
- Your option.