CI Cache Optimizer
Expert in reducing CI/CD build times through dependency caching, Docker layer caching, and build pipeline optimization.
Activation Triggers
Activate on: "CI cache", "build speed", "dependency caching", "Docker layer cache", "turbo remote cache", "GitHub Actions cache", "pnpm store cache", "slow builds", "CI optimization"
NOT for: Pipeline creation → github-actions-pipeline-builder | Deployment strategy → blue-green-deployment-orchestrator | Docker builds → docker-multi-stage-optimizer
Quick Start
- Profile the build — measure time per step to find the bottleneck (usually dependency install or Docker builds)
- Cache dependencies — restore package manager cache (pnpm store, pip cache, Go module cache)
- Cache Docker layers — use BuildKit cache or GitHub Actions Docker cache
- Cache build outputs — Turborepo remote cache, Next.js build cache, compiled artifacts
- Parallelize — split test suites, build independent packages concurrently
Core Capabilities
| Domain |
Technologies |
| Dependency Cache |
pnpm store, npm cache, pip cache, Go module cache, Cargo registry |
| Docker Cache |
BuildKit inline cache, GitHub Actions gha cache, registry cache |
| Build Cache |
Turborepo remote cache, Nx Cloud, Gradle build cache, ccache |
| CI Platforms |
GitHub Actions, GitLab CI, CircleCI, Buildkite |
| Analysis |
GitHub Actions timing, CI Insights, custom duration metrics |
Architecture Patterns
GitHub Actions Dependency Cache (pnpm)
# .github/workflows/ci.yml
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 22
cache: 'pnpm' # Built-in pnpm cache support
# Turbo remote cache for monorepo build outputs
- name: Build
run: pnpm turbo build --cache-dir=.turbo
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
Docker Layer Cache Strategies
# Strategy 1: GitHub Actions cache backend (fastest for GHA)
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: myapp:latest
cache-from: type=gha
cache-to: type=gha,mode=max
# Strategy 2: Registry cache (works across CI providers)
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: registry.io/myapp:latest
cache-from: type=registry,ref=registry.io/myapp:cache
cache-to: type=registry,ref=registry.io/myapp:cache,mode=max
Cache Hierarchy (What to Cache, in Priority Order)
Priority 1 — Dependency install (biggest time save):
├─ pnpm store: ~/.local/share/pnpm/store
├─ pip cache: ~/.cache/pip
├─ Go modules: ~/go/pkg/mod
└─ Cargo registry: ~/.cargo/registry
Priority 2 — Build outputs (incremental builds):
├─ Turbo remote cache: .turbo/
├─ Next.js: .next/cache
├─ TypeScript: tsconfig.tsbuildinfo
└─ Webpack: node_modules/.cache
Priority 3 — Docker layers (image builds):
├─ BuildKit cache mounts
├─ Docker layer cache (gha or registry)
└─ Multi-stage build ordering
Priority 4 — Test artifacts (expensive to regenerate):
├─ Playwright browsers: ~/.cache/ms-playwright
├─ Cypress: ~/.cache/Cypress
└─ Snapshot baselines
Anti-Patterns
- Caching node_modules directly — fragile and large. Cache the pnpm/npm store instead; the install step uses the cached store and is near-instant.
- No cache key versioning — stale caches cause mysterious failures. Include lockfile hash in the cache key:
key: deps-${{ hashFiles('pnpm-lock.yaml') }}.
- Caching everything — caching small files that are fast to regenerate wastes time on cache download. Only cache what saves more time than the restore cost.
- Missing restore-keys fallback — if the exact cache key misses, the build starts cold. Use
restore-keys with prefix matching for partial cache hits.
- Not profiling first — adding caching without knowing the bottleneck. Measure step durations first; the slowest step gets caching priority.
Quality Checklist
[ ] CI build time profiled and bottleneck identified
[ ] Dependency cache uses lockfile hash as cache key
[ ] Fallback restore-keys configured for partial hits
[ ] Docker builds use BuildKit with cache-from/cache-to
[ ] Turbo/Nx remote cache enabled for monorepo builds
[ ] Test browser binaries cached (Playwright, Cypress)
[ ] Cache size monitored (GitHub Actions: 10GB limit)
[ ] Stale caches cleaned via retention or key rotation
[ ] Parallel jobs configured for independent packages
[ ] Build time target set (e.g., < 5 minutes for PR checks)
[ ] Cache hit rate tracked (> 80% target)
[ ] Before/after metrics documented for optimization efforts
1---
2license: Apache-2.0
3name: ci-cache-optimizer
4description: "CI/CD caching optimizer for dependency caching, Docker layer caching, and build speed improvements. Activate on: CI cache, build speed, dependency caching, Docker layer cache, turbo remote cache, GitHub Actions cache, pnpm store cache. NOT for: CI/CD pipeline creation (use github-actions-pipeline-builder), deployment strategy (use blue-green-deployment-orchestrator), Docker image building (use docker-multi-stage-optimizer)."
5allowed-tools: Read,Write,Edit,Bash(docker:*,kubectl:*,terraform:*,npm:*,npx:*)
6category: DevOps & Infrastructure
7tags:
8 - ci-cd
9 - caching
10 - performance
11 - build-speed
12pairs-with:
13 - skill: github-actions-pipeline-builder
14 reason: Pipeline builder creates workflows; this skill optimizes their speed
15 - skill: docker-multi-stage-optimizer
16 reason: Docker layer caching is a key CI performance lever
17metadata:
18 source: https://skillmd.com/skills/curiositech/ci-cache-optimizer
19---
20
21# CI Cache Optimizer
22
23Expert in reducing CI/CD build times through dependency caching, Docker layer caching, and build pipeline optimization.
24
25## Activation Triggers
26
27**Activate on:** "CI cache", "build speed", "dependency caching", "Docker layer cache", "turbo remote cache", "GitHub Actions cache", "pnpm store cache", "slow builds", "CI optimization"
28
29**NOT for:** Pipeline creation → `github-actions-pipeline-builder` | Deployment strategy → `blue-green-deployment-orchestrator` | Docker builds → `docker-multi-stage-optimizer`
30
31## Quick Start
32
331. **Profile the build** — measure time per step to find the bottleneck (usually dependency install or Docker builds)
342. **Cache dependencies** — restore package manager cache (pnpm store, pip cache, Go module cache)
353. **Cache Docker layers** — use BuildKit cache or GitHub Actions Docker cache
364. **Cache build outputs** — Turborepo remote cache, Next.js build cache, compiled artifacts
375. **Parallelize** — split test suites, build independent packages concurrently
38
39## Core Capabilities
40
41| Domain | Technologies |
42|--------|-------------|
43| **Dependency Cache** | pnpm store, npm cache, pip cache, Go module cache, Cargo registry |
44| **Docker Cache** | BuildKit inline cache, GitHub Actions gha cache, registry cache |
45| **Build Cache** | Turborepo remote cache, Nx Cloud, Gradle build cache, ccache |
46| **CI Platforms** | GitHub Actions, GitLab CI, CircleCI, Buildkite |
47| **Analysis** | GitHub Actions timing, CI Insights, custom duration metrics |
48
49## Architecture Patterns
50
51### GitHub Actions Dependency Cache (pnpm)
52
53```yaml
54# .github/workflows/ci.yml
55- uses: pnpm/action-setup@v4
56 with:
57 version: 9
58
59- uses: actions/setup-node@v4
60 with:
61 node-version: 22
62 cache: 'pnpm' # Built-in pnpm cache support
63
64# Turbo remote cache for monorepo build outputs
65- name: Build
66 run: pnpm turbo build --cache-dir=.turbo
67 env:
68 TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
69 TURBO_TEAM: ${{ vars.TURBO_TEAM }}
70```
71
72### Docker Layer Cache Strategies
73
74```yaml
75# Strategy 1: GitHub Actions cache backend (fastest for GHA)
76- uses: docker/build-push-action@v6
77 with:
78 context: .
79 push: true
80 tags: myapp:latest
81 cache-from: type=gha
82 cache-to: type=gha,mode=max
83
84# Strategy 2: Registry cache (works across CI providers)
85- uses: docker/build-push-action@v6
86 with:
87 context: .
88 push: true
89 tags: registry.io/myapp:latest
90 cache-from: type=registry,ref=registry.io/myapp:cache
91 cache-to: type=registry,ref=registry.io/myapp:cache,mode=max
92```
93
94### Cache Hierarchy (What to Cache, in Priority Order)
95
96```
97Priority 1 — Dependency install (biggest time save):
98 ├─ pnpm store: ~/.local/share/pnpm/store
99 ├─ pip cache: ~/.cache/pip
100 ├─ Go modules: ~/go/pkg/mod
101 └─ Cargo registry: ~/.cargo/registry
102
103Priority 2 — Build outputs (incremental builds):
104 ├─ Turbo remote cache: .turbo/
105 ├─ Next.js: .next/cache
106 ├─ TypeScript: tsconfig.tsbuildinfo
107 └─ Webpack: node_modules/.cache
108
109Priority 3 — Docker layers (image builds):
110 ├─ BuildKit cache mounts
111 ├─ Docker layer cache (gha or registry)
112 └─ Multi-stage build ordering
113
114Priority 4 — Test artifacts (expensive to regenerate):
115 ├─ Playwright browsers: ~/.cache/ms-playwright
116 ├─ Cypress: ~/.cache/Cypress
117 └─ Snapshot baselines
118```
119
120## Anti-Patterns
121
1221. **Caching node_modules directly** — fragile and large. Cache the pnpm/npm store instead; the install step uses the cached store and is near-instant.
1232. **No cache key versioning** — stale caches cause mysterious failures. Include lockfile hash in the cache key: `key: deps-${{ hashFiles('pnpm-lock.yaml') }}`.
1243. **Caching everything** — caching small files that are fast to regenerate wastes time on cache download. Only cache what saves more time than the restore cost.
1254. **Missing restore-keys fallback** — if the exact cache key misses, the build starts cold. Use `restore-keys` with prefix matching for partial cache hits.
1265. **Not profiling first** — adding caching without knowing the bottleneck. Measure step durations first; the slowest step gets caching priority.
127
128## Quality Checklist
129
130```
131[ ] CI build time profiled and bottleneck identified
132[ ] Dependency cache uses lockfile hash as cache key
133[ ] Fallback restore-keys configured for partial hits
134[ ] Docker builds use BuildKit with cache-from/cache-to
135[ ] Turbo/Nx remote cache enabled for monorepo builds
136[ ] Test browser binaries cached (Playwright, Cypress)
137[ ] Cache size monitored (GitHub Actions: 10GB limit)
138[ ] Stale caches cleaned via retention or key rotation
139[ ] Parallel jobs configured for independent packages
140[ ] Build time target set (e.g., < 5 minutes for PR checks)
141[ ] Cache hit rate tracked (> 80% target)
142[ ] Before/after metrics documented for optimization efforts
143```