Share Turborepo Cache Across CI and Developers
Configure remote caching, declare task inputs and outputs precisely, and use the cache so a task already run anywhere is not repeated locally or in CI.
Task
Enable remote caching in Turborepo so builds and tests are reused across machines.
When to use this
Every developer and CI job redoes the same builds and tests because the cache is local, wasting minutes on every change.
Prerequisites
- A Turborepo monorepo
- A remote cache provider or self-hosted cache
Steps
1. Connect the repo to a remote cache and authenticate in CI.
Expected output: Cache artifacts are shared.
2. Declare each task inputs and outputs in turbo.json.
Expected output: Cache keys reflect real dependencies.
3. Verify a task run in CI is a cache hit for a developer with no changes.
Expected output: The cache is actually shared.
4. Keep secrets out of cached outputs and exclude environment files from inputs when unsafe.
npx turbo run build --dry=json | head -40Expected output: Caching does not leak values.
Troubleshooting
Problem
Cache never hits across machines
Solution
Check input declarations and that all machines point at the same remote cache with valid auth.
Problem
Stale cache used
Solution
If inputs omit a relevant file, a stale artifact is served; include all task inputs.
Limitations
- Remote caching uploads task outputs to a shared store, which must be secured and access-controlled.
- Incorrect input declarations cause either missed hits or stale artifacts, so they need care.
Context
Enable remote caching in Turborepo so builds and tests are reused across machines. Every developer and CI job redoes the same builds and tests because the cache is local, wasting minutes on every change.
Steps
- Connect the repo to a remote cache and authenticate in CI. Expected: Cache artifacts are shared.
- Declare each task inputs and outputs in turbo.json. Expected: Cache keys reflect real dependencies.
- Verify a task run in CI is a cache hit for a developer with no changes. Expected: The cache is actually shared.
- Keep secrets out of cached outputs and exclude environment files from inputs when unsafe. Expected: Caching does not leak values.
{
"pipeline": {
"build": { "dependsOn": ["^build"], "outputs": ["dist/**"] },
"test": { "dependsOn": ["build"], "inputs": ["src/**", "test/**"] }
}
}
Verify
- Cache artifacts are shared.
- Cache keys reflect real dependencies.
- The cache is actually shared.
- Caching does not leak values.
Limits
- Remote caching uploads task outputs to a shared store, which must be secured and access-controlled.
- Incorrect input declarations cause either missed hits or stale artifacts, so they need care.