Repository navigation
Move cache v1 and v2 implementations behind a CacheBackend interface - #2573
Open
diogotorres97 wants to merge 1 commit into
Open
diogotorres97 wants to merge 1 commit into
diogotorres97 wants to merge 1 commit into
Conversation
diogotorres97
marked this pull request as ready for review
November 11, 2026 18:45
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor only, no behaviour change. This is the first step proposed in #2572 (an optional, administrator-configured S3 storage backend for self-hosted runners).
What changes
restoreCache,saveCacheandisFeatureAvailableincache.tseach switched on the cache service version. The switch now lives in one place,getCacheBackend(version), which returns aCacheBackend:internal/backends/v1.tsandinternal/backends/v2.tsholdrestoreCacheV1/saveCacheV1andrestoreCacheV2/saveCacheV2, moved verbatim (diffed against the originalcache.ts), each with its ownisAvailable()that holds the same env check as before.cache.tskeeps the public entry points, path and key validation, and theACTIONS_CACHE_MODEchecks, then hands off to the backend.cache write/read denied:prefixes move tointernal/errors.ts, andcheckPaths/checkKeymove tointernal/validation.ts. The backends need them, and importing them fromcache.tswould create a circular import.cache.tsre-exports every error class and constant, so the public API andinstanceofchecks are unchanged: the exported names inlib/cache.d.tsmatch before and after.Why
A new backend becomes one file implementing
CacheBackendplus one case ingetCacheBackend, without touching the existing v1/v2 paths. That keeps a follow-up S3 backend PR small and lets it be reviewed in isolation.Testing
npm run format-checkandeslintpass on the package, andtsc --noEmitpasses.jest packages/cache: all 150 existing tests pass, unchanged. A newcacheBackends.test.tscoversgetCacheBackenddispatch (v1, v2, unknown version falling back to v1) and each backend'sisAvailable(), for 155 in total.