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

Cached records are cleared without regard to Vary header #173

Open
stickystyle opened this issue Nov 20, 2017 · 1 comment
Open

Cached records are cleared without regard to Vary header #173

stickystyle opened this issue Nov 20, 2017 · 1 comment

Comments

@stickystyle
Copy link

I'm accessing a REST API that returns different data structures based on the Accept header. Cachecontrol seems to be properly handling the Vary: Accept, Accept-Encoding that the server sends back when making requests, that's good. What becomes an issue is when one of the content type variants send back Cache-Control: no-store, Cachecontrol just blows away the other cached record without regard to the secondary key provided by Vary.

https://github.com/ionrock/cachecontrol/blob/db54c4033cbf49489a1cf54586d2f6ae6c66813f/cachecontrol/controller.py#L287-L289

@patrickporto
Copy link

You can make a cache controller for drop the header Cache-Control. Example:

from cachecontrol.controller import CacheController

class CustomCacheController(CacheController):
    def cache_response(self, request, response, *args, **kwargs):
        response.headers.pop('Cache-Control')
        super().cache_response(request, response, *args, **kwargs)


sess = requests.Session()
sess.mount('http://', CacheControlAdapter(...,controller_class=CustomCacheController))

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

No branches or pull requests

2 participants