How to use the cachecontrol.caches 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 pymedusa / Medusa / lib / tvrage_api / tvrage_api.py View on Github external
    @retry(tvrage_error)
    def _loadUrl(self, url, params=None):
        try:
            log().debug("Retrieving URL %s" % url)

            # get response from TVRage
            if self.config['cache_enabled']:
                session = CacheControl(sess=self.config['session'], cache=caches.FileCache(self.config['cache_location']), cache_etags=False)
                if self.config['proxy']:
                    log().debug("Using proxy for URL: %s" % url)
                    session.proxies = {
                        "http": self.config['proxy'],
                        "https": self.config['proxy'],
                    }

                resp = session.get(url.strip(), params=params)
            else:
                resp = requests.get(url.strip(), params=params)

            resp.raise_for_status()
        except requests.exceptions.HTTPError, e:
            raise tvrage_error("HTTP error " + str(e.errno) + " while loading URL " + str(url))
        except requests.exceptions.ConnectionError, e:
            raise tvrage_error("Connection error " + str(e.message) + " while loading URL " + str(url))
github conda / conda-build / conda_build / skeletons / cran.py View on Github external
def get_session(output_dir, verbose=True):
    session = requests.Session()
    try:
        import cachecontrol
        import cachecontrol.caches
    except ImportError:
        if verbose:
            print("Tip: install CacheControl (conda package) to cache the CRAN metadata")
    else:
        session = cachecontrol.CacheControl(session,
            cache=cachecontrol.caches.FileCache(join(output_dir,
                '.web_cache')))
    return session
github biolab / orange3-imageanalytics / orangecontrib / imageanalytics / utils / embedder_utils.py View on Github external
def __init__(self):
        self._session = cachecontrol.CacheControl(
            requests.session(),
            cache=cachecontrol.caches.FileCache(
                join(cache_dir(), __name__ + ".ImageEmbedder.httpcache")
            ),
github conda / conda-build / conda_build / cran.py View on Github external
def get_session(output_dir, verbose=True, cache=[]):
    if cache:
        return cache[0]
    session = requests.Session()
    try:
        import cachecontrol
        import cachecontrol.caches
    except ImportError:
        if verbose:
            print("Tip: install CacheControl to cache the CRAN metadata")
    else:
        session = cachecontrol.CacheControl(session,
            cache=cachecontrol.caches.FileCache(join(output_dir,
                '.web_cache')))

    cache.append(session)
    return session
github biolab / orange3-imageanalytics / orangecontrib / imageanalytics / local_embedder.py View on Github external
def __init__(self, model, model_settings):
        self.model = model
        self._load_model()

        self._target_image_size = model_settings["target_image_size"]

        self._session = cachecontrol.CacheControl(
            requests.session(),
            cache=cachecontrol.caches.FileCache(
                join(cache_dir(), __name__ + ".ImageEmbedder.httpcache")
            ),
        )

        self._cancelled = False

        self._image_loader = ImageLoader()
        self._cache = EmbedderCache(model)