Add a parameter to ignore the existing cache but still store the cache at the end
See original GitHub issueFeature Request
Description
Add a parameter “no-restore” that will ignore the existing cache but still store the cache at the end of the job.
Use Case
I’m building a Rust project and I try to keep a cache “main” that is used in fallback of PR if there is no pre-existing cache for that PR. In other words, newly created PR use this cache as “base”.
Unfortunately the dependencies can change, the version of the compiler too, and the target (build) directory gets bigger over time.
I don’t need a cache on the main branch, I only use it to accelerate the first build of the PR. So it would be nice to have a flag “no-restore” that would ignore the existing cache but still save and replace the cache at the end.
Workaround
In the workflow that builds the main branch:
- name: Get main commit hash
id: main_commit
run: echo "::set-output name=hash::$(git rev-parse origin/main)"
- name: Cache target, rustup and cargo registry
id: cache-target
uses: actions/cache@v2
with:
path: |
~/.rustup
~/.cargo/registry
~/.cargo/bin
target
key: main-${{ steps.main_commit.outputs.hash }}
In the workflow that builds the PR:
- name: Get main commit hash
id: main_commit
run: echo "::set-output name=hash::$(git rev-parse origin/main)"
- name: Cache target, rustup and cargo registry
id: cache-target
uses: actions/cache@v2
with:
path: |
~/.rustup
~/.cargo/registry
~/.cargo/bin
target
key: ${{ github.event.issue.number }}-${{ runner.os }}-pr
restore-keys: main-${{ steps.main_commit.outputs.hash }}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:8
Top Results From Across the Web
Advanced topics on caching in Apollo Client
This article describes special cases and considerations when using the Apollo Client cache. Bypassing the cache. Sometimes you shouldn't use the cache for...
Read more >Cache-Control - HTTP - MDN Web Docs
The Cache-Control HTTP header field holds directives (instructions) — in both requests and responses — that control caching in browsers and ...
Read more >javascript - Cache busting via params - Stack Overflow
No. The parameter will not change the caching policy; the caching headers sent by the server still apply, and if it doesn't send...
Read more >Caching in GitLab CI/CD
Use cache for dependencies, like packages you download from the internet. Cache is stored where GitLab Runner is installed and uploaded to S3...
Read more >Build Cache - Gradle User Manual
But instead of being limited to the previous build in the same workspace, task output caching allows Gradle to reuse task outputs from...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Putting the git SHA hash into the key means that you will be saving a new cache each time. That’s way too often! Because the cache is limited in size, old stuff will expire too frequently!
Think about what functions we’d actually like from a cache:
This GitHub action does the first two but there is no way to do the third. If the entry exists, you can’t overwrite it. That’s why you need a way to force an overwrite. That’s what I did in my PR linked above.
You can mess around with the cache key and restore-keys but you’ll not find a way to update an existing key. So either you can’t refresh or you get a solution that will churn the cache entries.
We also have a need for this: In our iOS project, we cache Carthage folder, but sometimes the cache becomes invalid even if it was a hit. In that case, we’d like to be able to invalidate cache.