How to use the cachecontrol.cache.DictCache function in CacheControl

To help you get started, we’ve selected a few CacheControl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ionrock / cachecontrol / tests / test_cache_control.py View on Github external
def test_cache_request_fresh_max_age(self):
        now = time.strftime(TIME_FMT, time.gmtime())
        resp = Mock(headers={"cache-control": "max-age=3600", "date": now})

        cache = DictCache({self.url: resp})
        self.c.cache = cache
        r = self.req({})
        assert r == resp
github ionrock / cachecontrol / tests / test_cache_control.py View on Github external
def test_cache_request_no_headers(self):
        cached_resp = Mock(headers={"ETag": "jfd9094r808", "Content-Length": 100})
        self.c.cache = DictCache({self.url: cached_resp})
        resp = self.req({})
        assert not resp
github ionrock / cachecontrol / tests / test_cache_control.py View on Github external
def test_cache_request_unfresh_max_age(self):
        earlier = time.time() - 3700  # epoch - 1h01m40s
        now = time.strftime(TIME_FMT, time.gmtime(earlier))
        resp = Mock(headers={"cache-control": "max-age=3600", "date": now})
        self.c.cache = DictCache({self.url: resp})
        r = self.req({})
        assert not r
github pymedusa / Medusa / medusa / helpers.py View on Github external
def make_session(cache_etags=True, serializer=None, heuristic=None):
    session = requests.Session()

    adapter = CacheControlAdapter(
        DictCache(),
        cache_etags=cache_etags,
        serializer=serializer,
        heuristic=heuristic,
    )

    session.mount('http://', adapter)
    session.mount('https://', adapter)

    session.cache_controller = adapter.controller

    session.headers.update({'User-Agent': USER_AGENT, 'Accept-Encoding': 'gzip,deflate'})

    return session
github ionrock / cachecontrol / cachecontrol / _cmd.py View on Github external
def get_session():
    adapter = CacheControlAdapter(
        DictCache(), cache_etags=True, serializer=None, heuristic=None
    )
    sess = requests.Session()
    sess.mount("http://", adapter)
    sess.mount("https://", adapter)

    sess.cache_controller = adapter.controller
    return sess
github jmcarp / requests-middleware / requests_middleware / contrib / cachecontrolware.py View on Github external
def __init__(self, cache=None, cache_etags=True, controller_class=None,
                 serializer=None, heuristic=None):
        self.cache = cache or DictCache()
        self.heuristic = heuristic
        controller_factory = controller_class or CacheController
        self.controller = controller_factory(
            self.cache,
            cache_etags=cache_etags,
            serializer=serializer,
        )
github ionrock / cachecontrol / cachecontrol / controller.py View on Github external
def __init__(
        self, cache=None, cache_etags=True, serializer=None, status_codes=None
    ):
        self.cache = DictCache() if cache is None else cache
        self.cache_etags = cache_etags
        self.serializer = serializer or Serializer()
        self.cacheable_status_codes = status_codes or (200, 203, 300, 301)