Why does GitHub Actions Cache not work as I expect for Rust?

On my local machine, if I build my project, change a line, then build again, it only displays compiling my-project (it doesn't compile all the dependencies.

On GitHub Actions, without using the Cache Action, it starts from the beginning, and shows "Downloading..." for each dependency, then "Compiling..." for each dependency, etc.

If I configure it to use the Cache Action, it simply removes the "Downloading..." step. It still shows "Compiling..." for every dependency from the beginning.

I've configured i exactly as they showed in the example, and it shows the cache is getting hit in the Actions CLI output, so it is working.

It's annoying that locally rebuilding my project takes a few seconds, but with GitHub Actions it will always take 15 minutes per run. I see @dakom was also experiencing this.

Any help would be appreciated.

What project is this for? Can you post the full GHA workflow specification?

FWIW, Swatinem/rust-cache is a wrapper around the GHA caching layer that sets up keys and what to cache in (rust-analyzer's opinion of) an optimal way for CI.

What it sounds like is that your target directory isn't getting cached.


Huh, I'll have to check that out myself. I'd basically given up on caching in CI because it was so bad.

I switched to using rust-cache and it seems to be working now. Thank you! Not sure what I was doing wrong with the normal cache Action. I was caching the entire ./target directory.

That cut CI compile times down from 15 minutes to 3 minutes. If I touch all my workspace crates and recompile on my local computer, it's still much faster (50 seconds). I think it's just my local computer has more cores than GHA's server.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.