Taskfile Smart Caching with Sources & Generates
Intermediatev1.0.0
Use Taskfile's sources and generates for intelligent task caching — skip tasks when inputs haven't changed, fingerprint-based detection, and status commands for custom cache logic.
Content
Overview
Taskfile can skip tasks when source files haven't changed since the last run. This makes builds incremental — only rebuild what's needed. Configure sources (inputs) and generates (outputs) for automatic detection, or use status for custom logic.
Why This Matters
- -Faster builds — skip unchanged tasks
- -Incremental CI — only re-lint changed files
- -Smart dependencies — rebuild only when sources change
- -No manual cache invalidation — Taskfile tracks fingerprints
How It Works
Step 1: File-Based Caching
Step 2: Status-Based Caching
Step 3: Combining Sources and Status
Step 4: Force Run (Bypass Cache)
Caching Methods
| Method | Use When |
|---|---|
| sources + generates | File transformation (compile, generate) |
| sources only | Validation tasks (lint, test) |
| status | Custom conditions (Docker image exists, deps installed) |
| --force | Bypass all caching |
Best Practices
- -Use sources for all build tasks — makes them incremental
- -Use status for installation checks — skip if already installed
- -Use glob patterns:
**/*.gomatches all Go files recursively - -Use --verbose to debug cache decisions
- -Combine sources + status for complex cache logic
Common Mistakes
- -Not using sources/generates (every run rebuilds from scratch)
- -Too broad glob patterns (cache never hits)
- -Too narrow glob patterns (misses changed files)
- -Forgetting --force when debugging cache issues
FAQ
Discussion
Loading comments...