Skip to content

Instantly share code, notes, and snippets.

@dstufft
Created April 23, 2014 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstufft/11213903 to your computer and use it in GitHub Desktop.
Save dstufft/11213903 to your computer and use it in GitHub Desktop.
diff --git a/pip/download.py b/pip/download.py
index 4c23f5e..f503320 100644
--- a/pip/download.py
+++ b/pip/download.py
@@ -18,6 +18,7 @@ from pip.util import (splitext, rmtree, format_size, display_path,
backup_dir, ask_path_exists, unpack_file,
create_download_cache_folder, cache_download)
from pip.vcs import vcs
+from pip.locations import HTTP_CACHE_DIR
from pip.log import logger
from pip._vendor import requests, six
from pip._vendor.requests.adapters import BaseAdapter
@@ -27,6 +28,9 @@ from pip._vendor.requests.exceptions import InvalidURL, ChunkedEncodingError
from pip._vendor.requests.models import Response
from pip._vendor.requests.structures import CaseInsensitiveDict
+from cachecontrol import CacheControlAdapter
+from cachecontrol.caches import FileCache
+
__all__ = ['get_file_content',
'is_url', 'url_to_path', 'path_to_url',
'is_archive_file', 'unpack_vcs_link',
@@ -225,11 +229,17 @@ class PipSession(requests.Session):
# Attach our Authentication handler to the session
self.auth = MultiDomainBasicAuth()
+ # Configure our Cache
+ adapter_kw = {"cache": FileCache(HTTP_CACHE_DIR)}
+
# Configure retries
if retries:
- http_adapter = requests.adapters.HTTPAdapter(max_retries=retries)
- self.mount("http://", http_adapter)
- self.mount("https://", http_adapter)
+ adapter_kw.update({"max_retries": retries})
+
+ http_adapter = CacheControlAdapter(**adapter_kw)
+
+ self.mount("http://", http_adapter)
+ self.mount("https://", http_adapter)
# Enable file:// urls
self.mount("file://", LocalFSAdapter())
diff --git a/pip/locations.py b/pip/locations.py
index 7a848cf..17df4d7 100644
--- a/pip/locations.py
+++ b/pip/locations.py
@@ -17,6 +17,9 @@ import pip.exceptions
install
+HTTP_CACHE_DIR = os.path.expanduser("~/Library/Caches/pip/http")
+
+
DELETE_MARKER_MESSAGE = '''\
This file is placed here by pip to indicate the source was put
here by pip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment