How to clear cache in GitHub Actions?

I am working on an R package and using GitHub Action (GHA) as a Continuous Integration (CI) provider. I cache R packages (dependencies) by using actions/cache . And now I want to clear all cache. How can I do that?

I also asked this question on Stack Overflow (with no answer yet) and I provided my code examples there:


Hi @GegznaV,

Glad to see you in Github Community Forum!

Cache is stored on Github server, currently it’s not supported to clear it manually. GitHub will automatically remove any cache entries that have not been accessed in over 7 days.

Please check the Usage limits and eviction policy for more details.


@weide-zhou Thanks for the note here. Not sure if you’re part of the team working on this, but if you can, please can you raise the issue as high as you can?

For context, right now, I need to empty my cache, because my CI is failing (an old cached docker layer is misbehaving).

It sounds like the only way of fixing this is to instruct my entire team to not use the CI/CD system (i.e. not push any code at all) for 7 days. That’s just not viable.

Every other CI service I’ve used has the ability to re-run without cache right there in a button, GHA desperately needs this “feature” (speech marks because it’s less of a feature and more of a basic requirement!!).

What if I change the name of my workflow file, as a workaround? Will that create a separate, new cache?


@thclark The only way currently to “clear” the cache is to change the key. For example, if your key is ${{ runner.os }}-foo-${{ hashFiles(...) }}, changing it to ${{ runner.os }}-foo-v2-${{ hashFiles(...) }} will force it to create the cache. Also be sure to update any restore-keys as well.

This requires a code change / commit. Some users have also taken to using a secret variable, where your key would look like ${{ runner.os }}-foo-${{ secrets.CACHE_VERSION }}-${{ hashFiles(...) }}. With this, you can “clear” the cache by changing the secret value which doesn’t require a commit.

This feature is on our radar, but it’s unfortunately lower priority than other initiatives at the moment.

(Also note that cache storage is free, so changing the key like this will not result in extra costs.)


Thanks @dhadka I found that this morning in the end and had meant to post it as a workaround, so cheers for saving me the trouble :slight_smile:

Actually what might be interesting is a more general feature in which any action could define certain commands: perhaps a minimalist jsonSchema/yamlSchema for a form, or simply commands that get triggered on button clicks.

If defined in the action code, these could be parsed to extend the github UI with an extra button or buttons. So actions/cache could define a 'Clear Cache` button that then shows up for those workflows that use it.

That’d be very cool; flexible and great for use cases like this


What key are you talking about here? Can you give me an example of how do this, I really don’t get it. In my github actions workflow file? Where do I get the hasfile from and what is foo? Don’t see anything simliar to what you written out.

The key is an arbitrary key you specify that is used as part of the inputs for the actions/cache action. It can be whatever you want.

- name: Cache multiple paths
  uses: actions/cache@v2
    # This is the key right here
    key: ${{ runner.os }}-SomeStringLiteral-${{ hashFiles('**/lockfiles') }}
    path: |

hashFiles(...) is a built in function in GitHub Actions that calculates a checksum of the file(s) passed in (either a path to a single file or a glob pattern. Here is the source code for it)

foo in this case is just an arbitrary string literal used as part of the key.

If you look at the actions/cache documentation, you’ll see that the cache is scoped based off a few things and one of them is the provided key. If you change the key, you get a cache miss. So, the suggested workaround is to change the key in some way so it results in a cache miss. They suggested changing the arbitrary string literal from foo to foo-v2.

If you’re using hashFiles() as part of the key, you could also just make a benign change to the file (or one of the files) specified in the hashFiles and push that change up (since the file has been changed, it will result a different checksum, and thus, a different key)

1 Like

For anyone else looking at this.

It is now 6/10/2022.

It appears it is finally on GitHub’s roadmap to provide a way to update/clear cache ourselves. Target is some time this quarter. Actions: Ability to list and delete caches (Cloud) · Issue #502 · github/roadmap · GitHub