AspNetCore.CacheOutput icon indicating copy to clipboard operation
AspNetCore.CacheOutput copied to clipboard

Conditionally disable caching

Open toburger opened this issue 5 years ago • 1 comments

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.

toburger avatar Nov 23 '21 15:11 toburger

There are a lot of ways to implement:

  1. Preprocessor directives (conditional compilation) in every place where CacheOutput attribute is being used (not really convenient as for me).
  2. Create your own attribute, inherited from existing CacheOutputAttribute, and override IsCachingAllowed method to always return false on condition.
  3. Your option.

Iamcerba avatar Nov 24 '21 13:11 Iamcerba