C.W.K.
Stream
Lesson 05 of 13 · published

Dependency caching

~13 min · cache, performance, actions/cache

Level 0Apprentice
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Cache 가 CI 의 가장 큰 단일 가속

처음 deps 설치 — 분 단위. 두 번째, warm cache — 초 단위. actions/cache 가 범용 primitive; setup-* action 은 내장 cache 단축 가짐.

Cache 두 방식

1) Built-in cache (권장)

  • actions/setup-python@v5 + cache: pip.
  • actions/setup-node@v4 + cache: npm / pnpm / yarn.
  • astral-sh/setup-uv@v3 + enable-cache: true.
  • actions/setup-go@v5 는 기본적으로 Go module cache.

2) 범용 actions/cache

  • path: — cache 할 거.
  • key: — 주 키. 보통 ${{ runner.os }}-deps-${{ hashFiles('**/lockfile') }}.
  • restore-keys: — 정확한 key 없으면 prefix 폴백.

Cache 함정

  • Cache 는 branch 범위. main 의 cache 는 다른 branch 에서도 보임 — 하지만 feature branch cache 는 main 에서 안 보임.
  • Repo 당 총 10GB cache. 오래된 cache 는 LRU 로 제거.
  • Build 출력 caching (dist/, .next/) 은 시간 절약하지만 정확성 위험 있음. 가끔 cold cache 로 build 가 여전히 작동하는지 검증.

Code

actions/cache — build 출력 범용 예제·yaml
      - name: Cache Next.js build
        uses: actions/cache@v4
        with:
          path: |
            ${{ github.workspace }}/.next/cache
          key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.tsx', '**/*.ts') }}
          restore-keys: |
            ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
            ${{ runner.os }}-nextjs-

External links

Exercise

최근 CI run 하나 열어. Caching 후보가 될 가장 느린 step 식별 (install? build? 둘 다?). 거기에 cache layer 추가. Re-run, wall-clock 비교.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.