You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem Description
Currently, the cache action either restores an existing cache on cache-hit, or generates a missing cache on cache-miss. It does not update the cache on cache-hit.
This works well for caching static dependencies, but not for caching build artefacts.
Proposed Solution
Add an option allowing the user to enable cache updates.
This should be false by default to retain backwards-compatibility.
Motivation
Some programming languages benefit greatly from build caching. C++ in conjunction with ccache is the prime example. Using caching commonly decreases compilation times by at least 70%. Medium-sized projects easily take 20 minutes to compile.
ccache also manages the cache size itself and automatically removes obsolete entries, thus the cache won't explode with continuous updates.
It also saves time and money for both user and provider. The environment will be happy too.
Reacted by Dominik Honnef, judge2020, David Bond, Zeno Wu, Dmitry Murzin, James Darabi, Abex, Tobias Reiher, Iain Bean, Björn Kautler and 194 more
Reacted by Dmitry Murzin, Samuel Williams, Ilya Solovyov, Matt, craffael, Cedric Pinson, Martin Šošić, Cam Smith, Yuya Kanai, Ryan Nett and 29 more
I'm having this issue when trying to use @actions/cache for reducing update time of the built-in MSYS2 installation on windows-latest virtual environments. The virtual environments are outdated quite fast, and currently 5503.95 MiB need to be downloaded and installed on each job. It takes 8-10 min.
This would also be super handy for persisting the test cache when using GitHub Actions in go projects. For example, I could download the latest test cache, run my tests then update the existing cache with the results of the tests in the current run.
This way, I can have a global test cache across all my workflow runs.
This would be super valuable for monorepo's where each subproject has its own dependencies it wants to cache and build so that upstream projects have faster build times.
I ran into the expectation that this was already the default behavior - so I wrote #392 under that assumption
Is there any workaround for forcing the update of the cache even on a hit? I can't think of any way...
In my case it would reduce the compilation time from 20 minutes to 3 minutes if I could use ccache for QT/C++.
Maybe save as ccache-${{ github.run_id }} and restore with restore key ccache-.
github.run_id is unique id for the workflow run, so every time a new cache is saved.
When restoring you will never have an exact match but then the ccache- restore key will restore the latest one that started with that string and in the end create a new one with the current state.
Reacted by Dmitry Murzin, Potaito, Jakub Beránek, MaxPeal, Martin Šošić, Jack Lloyd, Sebastian Thomschke, Rob Cowsill, Ansgar Klein, Semyon Levin and 31 more
Reacted by Andreas Abel, Terry Chan and Jonas Kondratavicius
Reacted by Potaito, Yonatan Bitton, Kevin Patterson and wchaws
@Vampire that's brilliant, thanks mate! You are right, forgot about the pattern matching that the cache finding does. Perhaps this is then a non-issue and your solution is the intended way of doing things?
Nah, that's merely a work-around.
It will fill up your 5 GiB of cache and then evict things that might not have been evicted if the cache would have been updatable.
Reacted by MaxPeal, Rob Cowsill, Tiziano Santoro, Sam Warring, Yonatan Bitton, Viktor Andersson, Jason Axelson, Jamie Scott, Scott Lamb, Lucas and 18 more
Reacted by MaxPeal, Jack Lloyd, Ansgar Klein, Adrian Schmidt and Bruno Alexandre Rosa
Explicitly reuses the key from the restore step in the delete and save steps, avoiding mismatches
- name: Restore cacheuses: actions/cache/restore@v4id: cache# ...# Other steps go here...# Delete the old cache on hit to emulate a cache update. See# https://github.com/actions/cache/issues/342.
- name: Delete old cacheenv:
GH_TOKEN: ${{ github.token }}if: steps.cache.outputs.cache-hit# Using `--repo` makes it so that this step doesn't require checking out the# repo first.run: gh cache delete --repo ${{ github.repository }} ${{ steps.cache.outputs.cache-primary-key }}
- name: Save cacheuses: actions/cache/save@v4# Save the cache even if build steps fail.if: always()with:
key: ${{ steps.cache.outputs.cache-primary-key }}# ...
Reacted by LE, iTrooz, Christophe Dervieux, Aggelos Karalias, Santeri Elo, Chris Tallman, John Molakvoæ, Fernando Mora, Raymond Zhang, feeRnt and 3 more
It seems like the restore/clear/save approach has a concurrency / race condition footgun? The error message actions/cache/save gives when you try to rewrite a cache makes me think multiple jobs can fight, like what happens if one job is trying to gh cache delete while another is actively writing to the cache?
Failed to save: Unable to reserve cache with key KEY, another job may be creating this cache.
Warning: Cache save failed.
Activity
eine commentedon Jun 4, 2020
I'm having this issue when trying to use @actions/cache for reducing update time of the built-in MSYS2 installation on
windows-latestvirtual environments. The virtual environments are outdated quite fast, and currently 5503.95 MiB need to be downloaded and installed on each job. It takes 8-10 min.As commented in msys2/setup-msys2#23, I'm trying to save
/var/cache/pacman/pkg/. However, actions/checkout@v2 allows to do it once only. Later executions skip it: https://github.com/eine/setup-msys2/runs/737062486?check_suite_focus=true#step:12:2Then, I tried using the npm package: https://www.npmjs.com/package/@actions/cache. Unfortunately, it fails: https://github.com/eine/setup-msys2/runs/738298072?check_suite_focus=true#step:4:116
As an alternative to updating an existing key, it would be feasible to remove it explicitly (ref #340).
davidsbond commentedon Jun 18, 2020
This would also be super handy for persisting the test cache when using GitHub Actions in go projects. For example, I could download the latest test cache, run my tests then update the existing cache with the results of the tests in the current run.
This way, I can have a global test cache across all my workflow runs.
zen0wu commentedon Jun 21, 2020
This also applies to things like webpack loader cache, small, have their own key management, needs to be updated each time
Mordil commentedon Aug 7, 2020
This would be super valuable for monorepo's where each subproject has its own dependencies it wants to cache and build so that upstream projects have faster build times.
I ran into the expectation that this was already the default behavior - so I wrote #392 under that assumption
potaito commentedon Aug 13, 2020
Is there any workaround for forcing the update of the cache even on a hit? I can't think of any way...
In my case it would reduce the compilation time from 20 minutes to 3 minutes if I could use ccache for QT/C++.
Vampire commentedon Aug 13, 2020
Maybe save as
ccache-${{ github.run_id }}and restore with restore keyccache-.github.run_id is unique id for the workflow run, so every time a new cache is saved.
When restoring you will never have an exact match but then the
ccache-restore key will restore the latest one that started with that string and in the end create a new one with the current state.potaito commentedon Aug 13, 2020
@Vampire that's brilliant, thanks mate! You are right, forgot about the pattern matching that the cache finding does. Perhaps this is then a non-issue and your solution is the intended way of doing things?
Vampire commentedon Aug 13, 2020
Nah, that's merely a work-around.
It will fill up your 5 GiB of cache and then evict things that might not have been evicted if the cache would have been updatable.
fix: force-update cache after each build
fix: force-update cache after each build
PathogenDavid commentedon Dec 12, 2020
@HebaruSan It won't save anything at all.
https://github.com/actions/toolkit/blob/73d5917a6b5ea646ac3173cfceb727ee914ff6ed/packages/cache/src/cache.ts#L166-L175
HebaruSan commentedon Dec 12, 2020
Duplicate of #171
Fix cache to update after each day's run
Fix cache to update after each day's run
58 remaining items
analyze action: workaround inability to overwrite cache key
ci: simplify cache overwriting
ci: simplify cache overwriting
langston-barrett commentedon Apr 2, 2025
For those using the restore/clear/save workaround, here is an updated version.
It:
gh(docs)ifto skip deletion when it is not necessaryrestorestep in thedeleteandsavesteps, avoiding mismatchesWestonThayer commentedon Sep 30, 2025
It seems like the restore/clear/save approach has a concurrency / race condition footgun? The error message
actions/cache/savegives when you try to rewrite a cache makes me think multiple jobs can fight, like what happens if one job is trying togh cache deletewhile another is actively writing to the cache?Workaround to update Astro cache in GitHub action
Delete Astro cache instead of creating new one on every workflow
Delete Astro cache instead of creating new one on every workflow
Delete Astro cache instead of creating new one on every workflow
Delete Astro cache instead of creating new one on every workflow
Delete Astro cache instead of creating new one on every workflow
Workaround to update Astro cache in GitHub action
Delete Astro cache instead of creating new one on every workflow
Delete Astro cache instead of creating new one on every workflow
Delete Astro cache instead of creating new one on every workflow