diff options
author | Florian Pritz <bluewind@xinu.at> | 2018-12-17 17:04:43 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2018-12-17 17:04:43 +0100 |
commit | 7c68605636c2c6f5a52ccf4c7536d87d67102a85 (patch) | |
tree | b9548b6ceff12f8a47aa47ccf126b4c27b1e0b18 /lib/App/ArchLinux/PackagerTools | |
parent | dd551123400beb2e1ec0048d2ed19d82af3cc102 (diff) | |
download | App-ArchLinux-PackagerTools-7c68605636c2c6f5a52ccf4c7536d87d67102a85.tar.gz App-ArchLinux-PackagerTools-7c68605636c2c6f5a52ccf4c7536d87d67102a85.tar.xz |
PackagesDetailsFetcher: Cache 02packages
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib/App/ArchLinux/PackagerTools')
-rw-r--r-- | lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm | 24 | ||||
-rw-r--r-- | lib/App/ArchLinux/PackagerTools/Config.pm | 4 |
2 files changed, 14 insertions, 14 deletions
diff --git a/lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm b/lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm index 88122da..79b149e 100644 --- a/lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm +++ b/lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm @@ -31,6 +31,7 @@ Returns a new instance. =cut method new($class: $context, $deps = {}) { + $deps->{config} //= App::ArchLinux::PackagerTools::Config->new($context); $deps->{cache} //= App::ArchLinux::PackagerTools::Cache->new($context); return $class->new_no_defaults($context, $deps); } @@ -54,20 +55,15 @@ Return the uncompressed data of the 02packages.details.txt.gz file. =cut method get_packages_data() { - my $data; - my $use_cpanplus_index = 1; - if ($use_cpanplus_index) { - # This is mostly for development so we don't go over the network on each run. - my $packages_file = "$ENV{HOME}/.cpanplus/02packages.details.txt.gz"; - run ['zcat', $packages_file], \undef, \$data or die $log->error("Failed to fetch and uncompress CPAN module index: $?")."\n"; - } else { - # TODO cache the details file locally - # TODO when we have a cache of this, remove the $use_cpanplus_index part since that is worse than having our own cache - # TODO make the cpan mirror configurable - run [qw(curl -s ), "https://cpan.metacpan.org/modules/02packages.details.txt.gz"], '|', ['zcat'], \$data or die $log->error("Failed to fetch and uncompress CPAN module index: $?")."\n"; - } - - return $data; + my $conf = $self->{deps}->{config}->get_config(); + my $cache_timeout = $conf->{cpan}->{cache_timeout}; + my $mirror_url = $conf->{cpan}->{mirror_url}; + return $self->{deps}->{cache}->compute('02packages', $cache_timeout, sub { + my $data; + $log->debugf("Fetching 02packages file from mirror: %s", $mirror_url); + run [qw(curl -s ), "$mirror_url/modules/02packages.details.txt.gz"], '|', ['zcat'], \$data or die $log->error("Failed to fetch and uncompress CPAN module index: $?")."\n"; + return $data; + }); } 1; diff --git a/lib/App/ArchLinux/PackagerTools/Config.pm b/lib/App/ArchLinux/PackagerTools/Config.pm index 531e517..bd92c17 100644 --- a/lib/App/ArchLinux/PackagerTools/Config.pm +++ b/lib/App/ArchLinux/PackagerTools/Config.pm @@ -104,6 +104,10 @@ method _get_default_config() { root_dir => path(($ENV{XDG_CACHE_HOME} // $ENV{HOME}."/.cache")."/perlpkg/v1/")->stringify(), cache_size => '50M', }, + cpan => { + cache_timeout => '60m', + mirror_url => 'https://cpan.metacpan.org/', + }, }; } |