question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a parameter to ignore the existing cache but still store the cache at the end

See original GitHub issue

Feature 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:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:8

github_iconTop GitHub Comments

1reaction
eyal0commented, Feb 8, 2021

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:

  1. Fetch from cache, possibly not finding a hit.
  2. Save to cache if there is no entry.
  3. Save to cache overwriting an entry.

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.

1reaction
b-onccommented, Dec 14, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found