Skip to main content
InterviewHubPRO
Section Overview
Q6

Question 6 of 50

Part 1: CI/CD Fundamentals & GitHub Actions Core (Junior / Entry-Level)

12%
CI/CD & GitHub Actions (50 Qs)•Part 1: CI/CD Fundamentals & GitHub Actions Core (Junior / Entry-Level)

How does caching work in GitHub Actions?

junior LevelMost AskedCode ExampleState ManagementCI/CD & DevOpsSystem Design

In Simple Words: Downloading dependencies (like node_modules or .m2) from scratch on every run consumes network bandwidth and slows CI down.

  • actions/setup-<runtime> Built-In Cache: Built-in caching flags (cache: 'npm', cache: 'pip', cache: 'maven') are recommended for standard language setups.
  • actions/cache@v4: Explicit caching for arbitrary directories based on a cache key (usually a hash of lockfiles). If the key matches, the directory is restored; otherwise, the job runs and saves the new cache.
yaml
- name: Cache Gradle Dependencies
  uses: actions/cache@v4
  with:
    path: ~/.gradle/caches
    key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
    restore-keys: |
      ${{ runner.os }}-gradle-