fix: skip cache save on exact primary key hit#91
Merged
Conversation
Owner
|
Thanks! |
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.
Summary
CACHE_MATCHED_KEY_STATEand compare it against the primary key before saving.Approach
This follows the same pattern used by the official GitHub Actions that wrap
@actions/cache:actions/cacheactions/setup-pythonactions/setup-nodeactions/setup-goAll of these save the restored key via
core.saveState()during the restore step, then compare it against the primary key in the post-run save step. If they match, the cache already exists and saving is skipped.cacheId !== -1check and removal of the"already exists"branchThe previous code caught errors from
cache.saveCache()and checkedmessage.includes('already exists')to handle duplicate saves. This branch was dead code in two ways:@actions/cachecatchesReserveCacheErrorinternally (both v1 and v2 code paths) and logs viacore.info()before returning-1. The error never propagates to the caller.ReserveCacheErrormessage is"Unable to reserve cache with key ..., another job may be creating this cache.", which does not contain the string"already exists".The new code checks
cacheId !== -1to align with the library's actual contract. Since@actions/cachealready logs the reason internally on every path that returns-1, no additional logging is needed from our side. The catch block now only handles genuinely unexpected errors.