From 09b8c091c6e84104e091d38f26887582c07b74d5 Mon Sep 17 00:00:00 2001 From: Netkas Date: Tue, 7 Feb 2023 15:34:08 -0500 Subject: [PATCH] File downloads now cache the URL as a pointer to the file reducing the number of times the same file is downloaded --- CHANGELOG.md | 4 ++++ src/ncc/Utilities/Functions.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3dcf5f..d08bbbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bug fix where resources are not decoded correctly when installing packages [#31](https://git.n64.cc/nosial/ncc/-/issues/42) - Fixed issue where dependency conflicts are thrown even when `--reinstall` is used +### Changed + +- File downloads now cache the URL as a pointer to the file reducing the number of times the same file is downloaded + ## [1.0.0] - 2022-01-29 ### Added diff --git a/src/ncc/Utilities/Functions.php b/src/ncc/Utilities/Functions.php index 0168bf9..f0ca84a 100644 --- a/src/ncc/Utilities/Functions.php +++ b/src/ncc/Utilities/Functions.php @@ -62,6 +62,7 @@ namespace ncc\Utilities; use ncc\Objects\RepositoryQueryResults; use ncc\Objects\RepositoryQueryResults\Files; use ncc\Objects\Vault\Entry; + use ncc\Runtime; use ncc\ThirdParty\jelix\Version\Parser; use ncc\ThirdParty\jelix\Version\VersionComparator; use ncc\ThirdParty\Symfony\Filesystem\Filesystem; @@ -599,6 +600,9 @@ namespace ncc\Utilities; */ public static function downloadGitServiceFile(string $url, ?Entry $entry=null): string { + if(RuntimeCache::get('download_cache.' . $url) !== null) + return RuntimeCache::get('download_cache.' . $url); + $out_path = Functions::getTmpDir() . "/" . basename($url); $httpRequest = new HttpRequest(); @@ -608,6 +612,7 @@ namespace ncc\Utilities; Console::out('Downloading file ' . $url); HttpClient::download($httpRequest, $out_path); + RuntimeCache::set('download_cache.' . $url, $out_path); return $out_path; }