2525
2626namespace vcpkg
2727{
28+ // / Unique identifier for a provider
29+ using ProviderId = size_t ;
30+
2831 struct CacheStatus
2932 {
33+ using ReaderProviders = std::vector<const IReadBinaryProvider*>;
34+
3035 bool should_attempt_precheck (const IReadBinaryProvider* sender) const noexcept ;
3136 bool should_attempt_restore (const IReadBinaryProvider* sender) const noexcept ;
37+ bool should_attempt_write_back (ProviderId provider_id) const noexcept ;
3238
3339 bool is_unavailable (const IReadBinaryProvider* sender) const noexcept ;
3440 const IReadBinaryProvider* get_available_provider () const noexcept ;
41+ ReaderProviders& get_unavailable_providers () noexcept ;
3542 bool is_restored () const noexcept ;
3643
3744 void mark_unavailable (const IReadBinaryProvider* sender);
3845 void mark_available (const IReadBinaryProvider* sender) noexcept ;
3946 void mark_restored () noexcept ;
47+ void mark_written_back (ProviderId provider_id) noexcept ;
4048
4149 private:
4250 CacheStatusState m_status = CacheStatusState::unknown;
@@ -75,7 +83,9 @@ namespace vcpkg
7583
7684 // / Called upon a successful build of `action` to store those contents in the binary cache.
7785 // / returns the number of successful uploads
78- virtual size_t push_success (const BinaryPackageWriteInfo& request, MessageSink& msg_sink) = 0;
86+ virtual size_t push_success (const BinaryPackageWriteInfo& request,
87+ MessageSink& msg_sink,
88+ CacheStatus& cache_status) = 0;
7989
8090 virtual bool needs_nuspec_data () const = 0;
8191 virtual bool needs_zip_file () const = 0;
@@ -103,6 +113,11 @@ namespace vcpkg
103113
104114 virtual LocalizedString restored_message (size_t count,
105115 std::chrono::high_resolution_clock::duration elapsed) const = 0;
116+
117+ // / Unique identifier for this provider.
118+ // /
119+ // / Used by the cache to exclude cache providers during the write-back phase.
120+ virtual ProviderId id () const = 0;
106121 };
107122
108123 struct UrlTemplate
@@ -114,44 +129,62 @@ namespace vcpkg
114129 std::string instantiate_variables (const BinaryPackageReadInfo& info) const ;
115130 };
116131
132+ struct GithubActionsInfo
133+ {
134+ };
135+
117136 struct NuGetRepoInfo
118137 {
119138 std::string repo;
120139 std::string branch;
121140 std::string commit;
122141 };
123142
143+ enum class CacheType
144+ {
145+ Read,
146+ Write,
147+ ReadWrite
148+ };
149+
150+ template <typename T>
151+ struct CacheProvider
152+ {
153+ ProviderId id;
154+ T source;
155+ CacheType cache_type;
156+
157+ [[nodiscard]] constexpr bool is_read () const noexcept
158+ {
159+ return cache_type == CacheType::Read || cache_type == CacheType::ReadWrite;
160+ }
161+
162+ [[nodiscard]] constexpr bool is_write () const noexcept
163+ {
164+ return cache_type == CacheType::Write || cache_type == CacheType::ReadWrite;
165+ }
166+ };
167+
168+ template <typename T>
169+ using ProviderList = std::vector<CacheProvider<T>>;
170+
124171 struct BinaryConfigParserState
125172 {
173+ ProviderId provider_count = 0 ;
126174 bool nuget_interactive = false ;
127175 std::set<StringLiteral> binary_cache_providers;
128176
129177 std::string nugettimeout = " 100" ;
130178
131- std::vector<Path> archives_to_read;
132- std::vector<Path> archives_to_write;
133-
134- std::vector<UrlTemplate> url_templates_to_get;
135- std::vector<UrlTemplate> url_templates_to_put;
136-
137- std::vector<std::string> gcs_read_prefixes;
138- std::vector<std::string> gcs_write_prefixes;
139-
140- std::vector<std::string> aws_read_prefixes;
141- std::vector<std::string> aws_write_prefixes;
179+ ProviderList<Path> archives;
180+ ProviderList<UrlTemplate> url_templates;
181+ ProviderList<std::string> gcs_prefixes;
182+ ProviderList<std::string> aws_prefixes;
142183 bool aws_no_sign_request = false ;
143-
144- std::vector<std::string> cos_read_prefixes;
145- std::vector<std::string> cos_write_prefixes;
146-
147- bool gha_write = false ;
148- bool gha_read = false ;
149-
150- std::vector<std::string> sources_to_read;
151- std::vector<std::string> sources_to_write;
152-
153- std::vector<Path> configs_to_read;
154- std::vector<Path> configs_to_write;
184+ ProviderList<std::string> cos_prefixes;
185+ Optional<CacheProvider<GithubActionsInfo>> gha;
186+ ProviderList<std::string> sources;
187+ ProviderList<Path> configs;
155188
156189 std::vector<std::string> secrets;
157190
@@ -182,7 +215,7 @@ namespace vcpkg
182215 // / executing `actions`.
183216 void fetch (View<InstallPlanAction> actions);
184217
185- bool is_restored (const InstallPlanAction& ipa) const ;
218+ Optional<CacheStatus> cache_status (const InstallPlanAction& ipa) const ;
186219
187220 // / Checks whether the `actions` are present in the cache, without restoring them. Used by CI to determine
188221 // / missing packages.
0 commit comments