diff --git a/HISTORY.rst b/HISTORY.rst index c41b936c..af16fbf2 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -44,6 +44,7 @@ PlatformIO 3.0 * Added global ``lib_extra_dirs`` option to ``[platformio]`` section for `Project Configuration File "platformio.ini" `__ (`issue #842 `_) +* Enabled caching by default for API requests and Library Manager (see `enable_cache `__ setting) * Changed a default exit combination for Device Monitor from ``Ctrl+]`` to ``Ctrl+C`` * Improved detecting of ARM mbed media disk for uploading * Improved Project Generator for CLion IDE when source folder contains nested items diff --git a/docs/userguide/cmd_settings.rst b/docs/userguide/cmd_settings.rst index 53e24627..88daa6cd 100644 --- a/docs/userguide/cmd_settings.rst +++ b/docs/userguide/cmd_settings.rst @@ -97,6 +97,16 @@ Check for the platform updates interval. Enable SSL for PlatformIO Services +.. _enable_cache: + +``enable_cache`` +^^^^^^^^^^^^^^^^ + +:Default: Yes +:Values: Yes/No + +Enable caching for API requests and Library Manager + .. _setting_force_verbose: ``force_verbose`` @@ -144,17 +154,21 @@ Examples 1. List all settings and theirs current values -.. code-block:: bash +.. code:: + + > platformio settings get - $ platformio settings get Name Value [Default] Description ------------------------------------------------------------------------------------------ - auto_update_libraries Yes Automatically update libraries (Yes/No) - auto_update_platforms Yes Automatically update platforms (Yes/No) + auto_update_libraries No Automatically update libraries (Yes/No) + auto_update_platforms No Automatically update platforms (Yes/No) check_libraries_interval 7 Check for the library updates interval (days) check_platformio_interval 3 Check for the new PlatformIO interval (days) check_platforms_interval 7 Check for the platform updates interval (days) + enable_cache Yes Enable caching for API requests and Library Manager + enable_ssl No Enable SSL for PlatformIO Services enable_telemetry Yes Telemetry service (Yes/No) + force_verbose No Force verbose output when processing environments 2. Show specified setting @@ -223,8 +237,12 @@ Examples Name Value [Default] Description ------------------------------------------------------------------------------------------ - auto_update_libraries Yes Automatically update libraries (Yes/No) - auto_update_platforms Yes Automatically update platforms (Yes/No) + auto_update_libraries No Automatically update libraries (Yes/No) + auto_update_platforms No Automatically update platforms (Yes/No) check_libraries_interval 7 Check for the library updates interval (days) check_platformio_interval 3 Check for the new PlatformIO interval (days) check_platforms_interval 7 Check for the platform updates interval (days) + enable_cache Yes Enable caching for API requests and Library Manager + enable_ssl No Enable SSL for PlatformIO Services + enable_telemetry Yes Telemetry service (Yes/No) + force_verbose No Force verbose output when processing environments diff --git a/platformio/app.py b/platformio/app.py index ef850a55..85279cac 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -56,6 +56,10 @@ DEFAULT_SETTINGS = { "description": "Enable SSL for PlatformIO Services", "value": False }, + "enable_cache": { + "description": "Enable caching for API requests and Library Manager", + "value": True + }, "enable_telemetry": { "description": ("Telemetry service BasePkgManager.FILE_CACHE_MAX_SIZE: + return dst_path + + with app.ContentCache() as cc: + cc.set(cache_key_fname, basename(dst_path), self.FILE_CACHE_VALID) + cc.set(cache_key_data, "DUMMY", self.FILE_CACHE_VALID) + shutil.copy(dst_path, cc.get_cache_path(cache_key_data)) + return dst_path @staticmethod def unpack(source_path, dest_dir): @@ -580,6 +602,8 @@ class BasePkgManager(PkgRepoMixin, PkgInstallerMixin): class PackageManager(BasePkgManager): + FILE_CACHE_VALID = None # disable package caching + @property def manifest_name(self): return "package.json" diff --git a/platformio/managers/platform.py b/platformio/managers/platform.py index 2f9c25f8..0ee5a4fb 100644 --- a/platformio/managers/platform.py +++ b/platformio/managers/platform.py @@ -27,6 +27,8 @@ from platformio.managers.package import BasePkgManager, PackageManager class PlatformManager(BasePkgManager): + FILE_CACHE_VALID = None # disable platform caching + def __init__(self, package_dir=None, repositories=None): if not repositories: repositories = [ diff --git a/platformio/util.py b/platformio/util.py index 303e4649..061ee2ee 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -482,22 +482,22 @@ def _get_api_result( def get_api_result(url, params=None, data=None, auth=None, cache_valid=None): - from platformio.app import LocalCache + from platformio.app import ContentCache total = 0 max_retries = 5 - cache_key = (LocalCache.key_from_args(url, params, data, auth) + cache_key = (ContentCache.key_from_args(url, params, data, auth) if cache_valid else None) while total < max_retries: try: - with LocalCache() as lc: + with ContentCache() as cc: if cache_key: - result = lc.get(cache_key) + result = cc.get(cache_key) if result is not None: return result result = _get_api_result(url, params, data) if cache_valid: - with LocalCache() as lc: - lc.set(cache_key, result, cache_valid) + with ContentCache() as cc: + cc.set(cache_key, result, cache_valid) return result except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e: