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?

1 Like

@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