From 1a8a36aabbdca691322f53d0926fe6ae83532398 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Tue, 28 Sep 2021 09:29:42 +0200 Subject: [PATCH] Limit time to live for cache availability during ci --- include/vcpkg/binarycaching.h | 10 ++++++++++ src/vcpkg/binarycaching.cpp | 16 +++++++++++++++- src/vcpkg/commands.ci.cpp | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/vcpkg/binarycaching.h b/include/vcpkg/binarycaching.h index b19a705b49..c60e18024d 100644 --- a/include/vcpkg/binarycaching.h +++ b/include/vcpkg/binarycaching.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -119,9 +120,18 @@ namespace vcpkg /// Returns a vector where each index corresponds to the matching index in `actions`. std::vector precheck(const VcpkgPaths& paths, View actions); + /// Sets the time in seconds from now after which "unavailable" entries will be checked again. + /// A non-positive value disables re-checking. + void set_ttl_for_unavailable(int seconds); + private: + /// Returns true when the lifetime for "unvailable" entries is exceeded. + bool must_recheck_unavailable_entries() const noexcept; + std::unordered_map m_status; std::vector> m_providers; + ElapsedTimer m_ttl_elapsed; + int m_ttl_for_unavailable = 0; }; ExpectedS parse_download_configuration(const Optional& arg); diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index 1748e51ba5..6eb45ec560 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -1146,6 +1146,20 @@ namespace vcpkg } } + void BinaryCache::set_ttl_for_unavailable(int seconds) + { + m_ttl_for_unavailable = seconds; + if (seconds > 0) + { + m_ttl_elapsed = ElapsedTimer::create_started(); + } + } + + bool BinaryCache::must_recheck_unavailable_entries() const noexcept + { + return m_ttl_for_unavailable > 0 && m_ttl_elapsed.elapsed().as().count() > m_ttl_for_unavailable; + } + RestoreResult BinaryCache::try_restore(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action) { const auto abi = action.package_abi().get(); @@ -1182,7 +1196,7 @@ namespace vcpkg continue; // this one already tried :) } - if (cache_status.is_unavailable(m_providers.size())) + if (cache_status.is_unavailable(m_providers.size()) && !must_recheck_unavailable_entries()) { break; } diff --git a/src/vcpkg/commands.ci.cpp b/src/vcpkg/commands.ci.cpp index db704ce3cc..12d26fed12 100644 --- a/src/vcpkg/commands.ci.cpp +++ b/src/vcpkg/commands.ci.cpp @@ -600,6 +600,7 @@ namespace vcpkg::Commands::CI StatusParagraphs status_db = database_load_check(paths); auto collection_timer = ElapsedTimer::create_started(); + binary_cache.set_ttl_for_unavailable(120); auto summary = Install::perform(args, action_plan, Install::KeepGoing::YES,