Skip to content
Discussion options

You must be logged in to vote

Here are some proven best practices for caching dependencies in GitHub Actions:

  1. Use the official actions/cache action
    Always prefer actions/cache@v4 for better performance and stability.

  2. Cache based on lock files
    Use package-lock.json, pnpm-lock.yaml, or yarn.lock in the cache key.
    This ensures correct cache invalidation when dependencies change.

  3. Separate cache per OS and Node version
    Include runner.os and Node version in the cache key to avoid conflicts.

  4. Cache the correct directories

    • npm: ~/.npm
    • yarn: ~/.cache/yarn
    • pnpm: ~/.pnpm-store
  5. Restore cache before installing dependencies
    Make sure the cache restore step runs before npm install / pnpm install / yarn install.

  6. Prefer p…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by canberkberen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions Build, test, and automate your deployment pipeline with world-class CI/CD other General topics and discussions that don't fit into other categories, but are related to GitHub Question Ask and answer questions about GitHub features and usage Welcome 🎉 Used to greet and highlight first-time discussion participants. Welcome to the community!
2 participants