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.

Same cache key not shared between different pull requests

See original GitHub issue

Hi, I’m not sure if this is a feature or a bug, but when we use the same cache key for different PRs (sequentially without a race condition), the second PR doesn’t find the cache even though the keys are the same and the first PR completes the workflow successfully (including cache upload).

I looked through the actions/cache code and I think it may be related to the scope attribute of the ArtifactCacheEntry object. I weren’t able to hack around the code to ignore this attribute, so I’m not 100% sure. The attribute does contain values that would point to the caches being scoped to different PRs, though (refs/pull/1660/merge and refs/pull/1661/merge on the two test pull requests I tried).

This is the setup we use:

      - uses: actions/cache@v1
        id: cache
        with:
          path: .github/vendor/bundle
          key: github-gems-${{ hashFiles('**/.github/Gemfile.lock') }}
          restore-keys: |
            github-gems-

The bundle is installing gems to the correct folder, since the cache is successfully fetched starting from the second commit on each pull request.

Let me know if I can provide more info. Thanks!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:9
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
dkubbcommented, Jul 3, 2020

@chrispat

I think it might be possible to allow for sharing writable caches across PRs targeting the same base within a repo

My assumption (before finding this thread) was that caches would be shared between branches in a single repository. I kept wondering why my merge commits were not using cache even though the cache key was identical to the parent commit’s build.

I would definitely love to see caches be shared between branches. I can understand wanting to avoid fork PRs from “poisoning the cache”, but I think it should be safe for all branches in a given repository to use a shared cache.

EDIT: A compromise might be that when a feature branch is merged into the default branch it’s cache could be merged into the default branch’s cache, and then the least recently used of this cache can be purged to bring it down under the limit. Worst case this is no worse than now, but best case we can use the same cache as the final commit in the feature branch.

4reactions
aminyacommented, Aug 4, 2022

This cache miss across different branches is creating anti-patterns in the way people work. It has been my experience that people do not create different branches or smaller pull requests because the build would start from scratch!

This should be fixed. It is not just a miss-documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CI pipeline with parallel jobs sharing the same cache can ...
A pipeline which runs jobs in parallel which share the same cache can ... key: stuff policy: pull paths: - cache script: -...
Read more >
Caching dependencies to speed up workflows - GitHub Docs
Multiple workflow runs in a repository can share caches. A cache created for a branch in a workflow run can be accessed and...
Read more >
Within what limits Github actions/cache work? - Stack Overflow
Yeah, GitHub's cache action has unintuitive behavior across branches. Pull request workflows don't share, and tag workflows never get a ...
Read more >
Cache dependencies in GitLab CI/CD
Sharing caches across different branches. If the files you are caching need to be shared across all branches and all jobs, you can...
Read more >
Understanding the cache key - Amazon CloudFront
Other values from the viewer request are not included in the cache key, by default. ... another request for the same object, as...
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