Interview Prep/GitHub Actions/Caching, Artifacts, Builds & Scans

Docker layer cache (`type=gha`) never hits on PR builds.

AdvancedTroubleshootingCaching, Artifacts, Builds & Scans
Answer

Likely causes → Cache only written from PR refs (invisible to other PRs), cache evicted due to the 10 GB quota, scope differs between writers and readers, or the build context changes early layers each time (copying source before installing dependencies).

Diagnose → gh cache list --key buildkit and build logs showing CACHED vs rebuilt layers.

Fix → Write cache from main, keep scopes consistent, reorder Dockerfile, consider registry cache.

Prevent → Monitor cache size and hit rates.

All GitHub Actions questions Roadmap: GitHub Actions

More on Caching, Artifacts, Builds & Scans