Cache-Control: no-cache breaks the middleware #81
Comments
@tinchou Thanks for the detailed investigation. We'll get this dealt with ASAP. One possible workaround would be to always set an
@muratg @DamianEdwards This is a patch candidate bug. |
Can confirm the workaround works for me. I implemented public class FakeResponseCachingFeature : IResponseCachingFeature
{
public string[] VaryByQueryKeys
{
get => null;
set { }
}
} |
@pranavkm we'll need to build a 1.1.1 branch for this. |
@Tratcher and I think the middleware needs to be fixed. The feature should be added regardless of whether the request is cacheable since it is used when generating the response. |
In other words, the request header |
Should clients be telling the server when not to use the cache?
Before using this middleware my implementation was based on IMemoryCache,
and I never thought about checking the headers because it was an
implementation detail of the server.
I've looked around but haven't found specific information.
|
@tinchou when it comes to HTTP-based response caching, yes, the client still maintains ability to send cache control headers, thus affecting upstream caching behavior. As a result, you shouldn't rely on whole response caching to control load on your application. Using The old docs for ASP.NET Caching (from the System.Web days) covers the differences quite nicely in this introduction. All that said, it might still be nice to have the response caching middleware support a mode whereby it ignores all client-based HTTP cache control headers, and instead acts as a completely server-controlled cache. |
@DamianEdwards yes, I think that would be my preferred scenario. Since I'm already encoding caching information in my But if the client can void my cache as they please, then that defeats the whole performance story. EDIT: I'm curious, why would anyone want the server to ignore the cache when told by the client? |
Because that's normally how HTTP-based caching works. There's a client, server, and any amount of intermediaries in between, and they all speak HTTP and participate in caching, using the same cache control headers. We should investigate the caching behavior of the popular edge caching appliances & services, along with other frameworks, to see how they differentiate these concerns. |
The Azure CDN doesn't respect an invalidation attempt using the Initial request for a stale image serves from the origin ...
Second request with
|
👍 I like this idea. If offered, I'll definitely use it. |
- Always add IresponseCachingFeatu8re before calling the next middleware #81 - Use If-Modified-Since instead of the incorrect If-Unmodified-Since header #83 - Handle proxy-revalidate in the same way as must-revalidate #83 - Handle max-stale with no specified limit #83 - Bypass cache lookup for no-cache but store the response #83 - Bypass response capturing and buffering when no-store is specified #83 - Replace IsRequestCacheable cache policy with three new independent policy checks to reflect these changes
- Always add IresponseCachingFeatu8re before calling the next middleware #81 - Use If-Modified-Since instead of the incorrect If-Unmodified-Since header #83 - Handle proxy-revalidate in the same way as must-revalidate #83 - Handle max-stale with no specified limit #83 - Bypass cache lookup for no-cache but store the response #83 - Bypass response capturing and buffering when no-store is specified #83 - Replace IsRequestCacheable cache policy with three new independent policy checks to reflect these changes - Modify middleware flow to accommodate cache policy updates
- Always add IresponseCachingFeatu8re before calling the next middleware #81 - Use If-Modified-Since instead of the incorrect If-Unmodified-Since header #83 - Handle proxy-revalidate in the same way as must-revalidate #83 - Handle max-stale with no specified limit #83 - Bypass cache lookup for no-cache but store the response #83 - Bypass response capturing and buffering when no-store is specified #83 - Replace IsRequestCacheable cache policy with three new independent policy checks to reflect these changes - Modify middleware flow to accommodate cache policy updates
Fixed in #88. Will need to back port to 1.1.1 in a separate issue. |
TL;DR: this breaks with the
Cache-Control: no-cache
header since theIResponseCachingFeature
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:
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 aFeature
of typeIResponseCachingFeature
: 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:
Cache-Control: no-cache
headerShimResponseStream
If you could give me any workaround until a fix is published I'd really appreciate it!
Thanks,
Martín.
The text was updated successfully, but these errors were encountered: