Skip to content

Cached records are cleared without regard to Vary header #173

Open

Description

@stickystyle

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

Activity

  1. patrickporto commented on May 9, 2018

    @patrickporto

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions