How to use CacheControl - 10 common examples

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_expires_heuristics.py View on Github external
def setup(self):
        self.sess = Session()
        self.cache_sess = CacheControl(self.sess, heuristic=ExpiresAfter(days=1))
github ionrock / cachecontrol / tests / test_storage_filecache.py View on Github external
def test_simple_lockfile_arg(self, tmpdir, value, expected):
        if value is not None:
            cache = FileCache(str(tmpdir), use_dir_lock=value)
        else:
            cache = FileCache(str(tmpdir))

        assert issubclass(cache.lock_class, expected)
        cache.close()
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 setup(self):
        self.c = CacheController(DictCache(), serializer=NullSerializer())
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 ionrock / cachecontrol / tests / test_max_age.py View on Github external
def sess(self, url):
        self.url = url
        self.cache = DictCache()
        sess = Session()
        sess.mount(
            "http://", CacheControlAdapter(self.cache, serializer=NullSerializer())
        )
        return sess
github ionrock / cachecontrol / tests / test_adapter.py View on Github external
def use_adapter():
    print("Using adapter")
    sess = Session()
    sess.mount("http://", CacheControlAdapter())
    return sess
github ionrock / cachecontrol / tests / test_adapter.py View on Github external
def test_close(self):
        cache = mock.Mock(spec=DictCache)
        sess = Session()
        sess.mount("http://", CacheControlAdapter(cache))

        sess.close()
        assert cache.close.called
github ionrock / cachecontrol / tests / test_expires_heuristics.py View on Github external
def setup(self):

        class NoopHeuristic(BaseHeuristic):
            warning = Mock()

            def update_headers(self, resp):
                return {}

        self.heuristic = NoopHeuristic()
        self.sess = CacheControl(Session(), heuristic=self.heuristic)