File downloads now cache the URL as a pointer to the file reducing the number of times the same file is downloaded

This commit is contained in:
Netkas 2023-02-07 15:34:08 -05:00
parent 070ad4caca
commit 09b8c091c6
2 changed files with 9 additions and 0 deletions

View file

@ -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

View file

@ -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;
}