Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache-Control header default to no-cache on subsequent request when using HttpCacheControlPolicy #36

Closed
CallMeLaNN opened this issue Jul 4, 2013 · 2 comments
Labels

Comments

@CallMeLaNN
Copy link

I am using AttributeBasedCacheControlPolicy with CacheControlHeaderValue that cache privately for a couple of days by default.

When I use HttpCacheControlPolicy(false, 600) in an action, the first request responded as expected "Cache-Control: public, must-revalidate, max-age=600". However the subsequent request (after 600 second or expired) , contain "Cache-Control: no-cache" even though the HTTP status is correct "304 Not Modified". I expect it should always "Cache-Control: public, must-revalidate, max-age=600" to perform 'sliding' expiration.

I inspect using Fiddler

@CallMeLaNN
Copy link
Author

Update:

Without using HttpCacheControlPolicy attribute, the default cache config like the code below also only applied on the first request as "Cache-Control: no-transform, must-revalidate, max-age=600". The subsequent request will be "304 Not Modified" with "Cache-Control: no-cache".

        cachingHandler.CacheControlHeaderProvider = (request, cfg) =>
        {
            return new System.Net.Http.Headers.CacheControlHeaderValue()
            {
                Private = false,
                MustRevalidate = true,
                NoTransform = true,
                MaxAge = TimeSpan.FromSeconds(600)
            };
        };

@aliostad
Copy link
Owner

aliostad commented Jul 5, 2013

The behaviour is correct. Cache Header directives are irrelevant for a 304 response since the cache headers must be sent with the original response:

If the status code is 304 (Not Modified), the cache uses the entity- body stored in the cache entry as the entity-body of this outgoing response.

As you can see, there is no mention of headers here. Hope this helps.

In terms of examples outside, sites implement 304 differently. I have seen one that sends cache control and another only ETag. As I said the headers are irrelevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants