Skip to content

Add option to restore cache only #663

Description

@ForsakenHarmony

Description:
It would be nice to have the option to restore only and not save.

Justification:
In bigger repos, it's easy to hit the 10gb cache limit. Not caching in PRs can help with this.
Right now, I have to manually delete caches to help keep the caches on main alive.

Are you willing to submit a PR?

References
actions/toolkit#1308
Swatinem/rust-cache#95 (has a save-if option https://github.com/Swatinem/rust-cache#example-usage)

Activity

  1. dmitry-shibanov commented on Jan 11, 2023

    @dmitry-shibanov
    Contributor

    Hello @ForsakenHarmony. Thank you for your report. We'll investigate the issue.

  2. desrosj commented on Oct 25, 2023

    @desrosj

    Found this searching for an open issue because I wanted to request the same feature. Some context on the specific use case I have.

    In workflows triggered with the pull_request_target event, the recommendation in the docs is as follows:

    Although the workflow runs in the context of the base of the pull request, you should make sure that you do not check out, build, or run untrusted code from the pull request with this event. Additionally, any caches share the same scope as the base branch. To help prevent cache poisoning, you should not save the cache if there is a possibility that the cache contents were altered.

    When using the setup-node action, I'd like to turn off cache saving for runs triggered with this event.

  3. hugo082 commented on Dec 28, 2023

    @hugo082

    It can also help when a GitHub matrix is used. On large matrices, we may end with concurrency on cache write, forcing the job to wait (more than 1m on my repo).

    Post job cleanup.
    /usr/bin/tar --posix -cf cache.tzst --exclude cache.tzst -P -C /home/runner/work/... --files-from manifest.txt --use-compress-program zstdmt
    Failed to save: Unable to reserve cache with key <KEY>, another job may be creating this cache. More details: Cache already exists. Scope: refs/heads/main, Key: <KEY>, Version: <HASH>
    
  4. marcferreiro commented on Jan 25, 2024

    @marcferreiro

    Hi! Do you have any plan about this? In our case, we're handling the cache with a custom system, so we'd love to save some time in our workflows by disabling the save step.

  5. maschwenk commented on Feb 14, 2024

    @maschwenk

    @ForsakenHarmony agree. In a big monorepo with 500+ open PRs and ~100 commits per day, the cache becomes unusable because there's too many circumstances where the main cache gets evicted because of hundreds of non-main caches. I can't decide if:

    1. I need to control which bits of my pipeline are restore-only
    2. I should automate purging all non-main caches

    But it feels like a little of both are necessary

  6. v-aparnajyothi-y commented on Oct 27, 2025

    @v-aparnajyothi-y
    Contributor

    Hello Everyone, Thanks everyone for your patience and contributions. This issue reported here has been addressed in PR #1419, which is now merged. The documentation helps cache state restoration handling.
    We are proceeding to close this issue as the related PR is merged, Please feel free to reach us in case of any further concerns to reopen this issue :)

  7. ForsakenHarmony commented on Nov 7, 2025

    @ForsakenHarmony
    Author

    @aparnajyothi-y that seems more like a workaround because you can no longer use the built in caching functionality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or request to improve the current logic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions