Skip to main content
skill CX Codex

caching-strategy-optimizer — Claude Code skill

The caching-strategy-optimizer skill configures CI/CD caching for dependencies, Docker layers, build outputs, and test results. Use it when installs, builds, or tests slow down the pipeline.

MIT 272 installs ★ 64 updated 2026-01-12

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add patricio0312rev/skills --skill caching-strategy-optimizer -a claude-code
Open on GitHub

What caching-strategy-optimizer does

The skill helps shape cache rules for npm, pnpm, Python pip, and Cargo. It also covers Docker layer caching with Buildx or a registry, plus caches for Next.js, Webpack, TypeScript, Jest, and Pytest. Cache keys use hashes from lock files or project files, while restore keys provide a fallback after smaller changes.

The included workflow patterns use actions/cache@v3, docker/setup-buildx-action@v3, and docker/build-push-action@v5. They also show how to log cache hits and compare pipeline timings before and after the change. GitHub Actions cache storage is limited to 10GB and expires after 7 days, so cache size and refresh behavior need a place in the design.

The skill is aimed at CI configurations where dependency, build, and test data need separate cache paths. Correct lock-file selection matters: a generic key can reuse the wrong data, while missing restore keys remove the fallback for minor edits.

What it helps with

  • configure dependency caches for npm, pnpm, pip, or Cargo
  • speed up Docker builds with layer caching
  • store Next.js, Webpack, or TypeScript build caches
  • cache Jest and Pytest results
  • compare pipeline timing before and after caching

Example prompts for the agent

  • Set up GitHub Actions caching for this project’s package-lock.json and add suitable restore-keys.
  • Add Docker layer caching with docker/setup-buildx-action@v3 and docker/build-push-action@v5.
  • Inspect cache hits and produce a before-and-after comparison for dependency installation, builds, and tests.

How to install caching-strategy-optimizer

1Skills CLI (Vercel)

npx skills add patricio0312rev/skills --skill caching-strategy-optimizer -a claude-code

2Manually: put the files in place

~/.claude/skills/caching-strategy-optimizer/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/caching-strategy-optimizer/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about caching-strategy-optimizer

How do I install caching-strategy-optimizer in Claude Code?

Run npx skills add patricio0312rev/skills --skill caching-strategy-optimizer -a claude-code, then check ~/.claude/skills/caching-strategy-optimizer/SKILL.md.

What does caching-strategy-optimizer do?

It helps configure CI/CD caches for dependencies, Docker layers, build outputs, and test results. It also covers cache-hit logging and before-and-after timing comparisons.

What should I account for in GitHub Actions cache design?

Tie keys to hashes of the relevant lock files and source files, then add restore keys for fallback matches. GitHub Actions cache storage has a 10GB limit and expires after 7 days.

Source text

SKILL.md · MIT
---
name: caching-strategy-optimizer
description: Optimizes CI/CD pipeline speed by implementing effective caching for dependencies, Docker layers, build outputs, and test results. Provides before/after performance metrics and best practices. Use for "CI caching", "pipeline optimization", "build speed", or "cache strategy".
---

# Caching Strategy Optimizer

Dramatically speed up CI pipelines with intelligent caching.

## Cache Key Strategy

### Package Manager Caches

```yaml
# NPM - Hash package-lock.json
- uses: actions/cache@v3
  with:
    path: ~/.npm
    key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
    restore-keys: |
      ${{ runner.os }}-npm-

# pnpm - More aggressive caching
- uses: pnpm/action-setup@v2
  with:
    version: 8

- uses: actions/cache@v3
  with:
    path: |
      ~/.pnpm-store
      node_modules
    key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
    restore-keys: |
      ${{ runner.os }}-pnpm-

# Python pip
- uses: actions/cache@v3
  with:
    path: ~/.cache/pip
    key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}

# Cargo/Rust
- uses: actions/cache@v3
  with:
    path: |
      ~/.cargo/bin/
      ~/.cargo/registry/index/
      ~/.cargo/registry/cache/
      ~/.cargo/git/db/
      target/
    key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
```

## Docker Layer Caching

### Using Buildx

```yaml
- name: Set up Docker Buildx
  uses: docker/setup-buildx-action@v3

- name: Build with cache
  uses: docker/build-push-action@v5
  with:
    context: .
    cache-from: type=gha
    cache-to: type=gha,mode=max
```

### Registry-based Cache

```yaml
- name: Build with registry cache
  uses: docker/build-push-action@v5
  with:
    context: .
    cache-from: type=registry,ref=myapp:buildcache
    cache-to: type=registry,ref=myapp:buildcache,mode=max
```

## Build Output Caching

```yaml
# Next.js cache
- uses: actions/cache@v3
  with:
    path: |
      ${{ github.workspace }}/.next/cache
    key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
    restore-keys: |
      ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
      ${{ runner.os }}-nextjs-

# Webpack cache
- uses: actions/cache@v3
  with:
    path: node_modules/.cache/webpack
    key: ${{ runner.os }}-webpack-${{ hashFiles('webpack.config.js') }}-${{ hashFiles('src/**') }}

# TypeScript build cache
- uses: actions/cache@v3
  with:
    path: |
      dist
      tsconfig.tsbuildinfo
    key: ${{ runner.os }}-tsc-${{ hashFiles('**/*.ts') }}
```

## Test Results Caching

```yaml
# Jest cache
- uses: actions/cache@v3
  with:
    path: /tmp/jest_rt
    key: ${{ runner.os }}-jest-${{ hashFiles('**/*.test.ts') }}

# Pytest cache
- uses: actions/cache@v3
  with:
    path: .pytest_cache
    key: ${{ runner.os }}-pytest-${{ hashFiles('**/*test*.py') }}
```

## Before/After Metrics

```markdown
## Before Optimization

- Total time: 12 minutes
- npm ci: 4 minutes
- Build: 5 minutes
- Tests: 3 minutes

## After Caching

- Total time: 3 minutes
- npm ci: 30 seconds (cache hit)
- Build: 1 minute (incremental)
- Tests: 1.5 minutes (cache hit)

**Improvement: 75% faster (12m → 3m)**
```

## Cache Hit Rate Monitoring

```yaml
- name: Check cache hit
  id: cache
  uses: actions/cache@v3
  with:
    path: node_modules
    key: ${{ runner.os }}-deps-${{ hashFiles('package-lock.json') }}

- name: Log cache status
  run: |
    if [ "${{ steps.cache.outputs.cache-hit }}" == "true" ]; then
      echo "✅ Cache hit - saved $(date -u -d @$SECONDS +%M:%S)"
    else
      echo "❌ Cache miss - installing from scratch"
    fi
```

## Best Practices

1. **Precise keys**: Include all dependencies in hash
2. **Restore keys**: Fallback to partial matches
3. **Multiple paths**: Cache related files together
4. **Size limits**: GitHub Actions limit is 10GB
5. **Expiration**: Caches expire after 7 days
6. **Mode=max**: Docker cache mode for better hits
7. **Monitor hits**: Track cache effectiveness

## Common Pitfalls

❌ **Too generic keys**: `key: deps` (always hits)
✅ **Specific keys**: `key: deps-${{ hashFiles('package-lock.json') }}`

❌ **Missing restore-keys**: Cache miss on minor changes
✅ **Restore keys**: Partial match fallback

❌ **Caching node_modules with wrong lock file**
✅ **Match lock file**: Hash the right lockfile

## Output Checklist

- [ ] Package manager cache configured
- [ ] Build output cache
- [ ] Docker layer cache (if applicable)
- [ ] Test cache configured
- [ ] Cache keys use file hashes
- [ ] Restore keys for fallback
- [ ] Before/after metrics documented
- [ ] Cache hit monitoring

© patricio0312rev · MIT · patricio0312rev/skills

Similar skills

All skills for DevOps and infrastructure →

From the same set148

The whole set →
structured-logging-standardizer structured-logging-standardizer sets up structured JSON logging with request correlation IDs using AsyncLocalStorage and pino. Keeps backend logs queryable and connected. CX Codex +1 273installs data-retention-archiving-planner data-retention-archiving-planner plans data retention policies, maps compliance requirements, and automates cold storage migration for databases. CX Codex +1 273installs reliability-strategy-builder reliability-strategy-builder builds a failure-handling plan for a service: circuit breaker, retries with backoff, fallback, bulkhead isolation and SLOs with error budgets. CX Codex +1 273installs e2e-test-builder e2e-test-builder generates end-to-end browser tests for Playwright and Cypress using Page Object patterns, test fixtures, and semantic selectors. CX Codex +1 273installs component-scaffold-generator component-scaffold-generator builds the skeleton of a React or Vue component: typed props, variants, a test file, a Storybook story and JSDoc with an example. It asks for a name and props, then writes the files. CX Codex +1 272installs git-hygiene-enforcer git-hygiene-enforcer is a Claude Code skill for setting commit and branch conventions, preparing PR templates, and documenting review steps for a consistent Git workflow. CX Codex +1 271installs pr-template-builder pr-template-builder builds GitHub pull request, issue and discussion templates in .github: markdown skeletons plus YAML forms with required fields. CX Codex +1 271installs langchain-workflow-builder langchain-workflow-builder is a Claude Code skill with TypeScript patterns for LangChain Runnable sequences, branching chains, ReAct agents, and Redis chat persistence. CX Codex +1 271installs

Project sponsors

Companies that keep this analytics open