cachecontrol icon indicating copy to clipboard operation
cachecontrol copied to clipboard

Cached records are cleared without regard to Vary header

Open stickystyle opened this issue 8 years ago • 1 comments

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

stickystyle avatar Nov 20 '17 20:11 stickystyle

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))

patrickporto avatar May 09 '18 22:05 patrickporto