Cache-Control: no-cache breaks the middleware #81
Description
TL;DR: this breaks with the Cache-Control: no-cache
header since the IResponseCachingFeature
feature is not set up and we hit this exception.
Hi,
I'm just starting with your middleware, and the basic functionality is great. I just specify a [ResponseCache]
and it gets cached automatically, which is awesome :).
But I'm getting an error 500 each time I do "Ctrl+F5" or I disable caching in the Chrome dev tools. The error is the one in the title:
An unhandled exception occurred while processing the request. InvalidOperationException: 'VaryByQueryKeys' requires the response cache middleware.
Microsoft.AspNetCore.Mvc.Internal.ResponseCacheFilter.OnActionExecuting(ActionExecutingContext context)
The error is the same as if I had not called app.UseResponseCaching();
or called it in the wrong order. The exact line is the following, which shows that it's checking for a Feature
of type IResponseCachingFeature
: https://github.com/aspnet/Mvc/blob/d8c6c4ab34e1368c1b071a01fcdcb9e8cc12e110/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseCacheFilter.cs#L132.
I investigated the source code and came to the conclusion that the error is produced because:
- Browsers send
Cache-Control: no-cache
header - The request is marked as not cacheable here
- Since it's not cacheable we skip the call to
ShimResponseStream
- And we don't set up the Feature for the next middlewares.
- So we end up with the mentioned exception in this line
If you could give me any workaround until a fix is published I'd really appreciate it!
Thanks,
Martín.