# Taskfile Caching Requirements
## Rule
All build, compilation, and code generation tasks MUST include sources/generates or status fields for intelligent caching. Tasks should only run when inputs change.
## Required Caching
```yaml
# MUST have caching: build tasks
build:
desc: Build application
sources:
- cmd/**/*.go
- internal/**/*.go
- go.mod
- go.sum
generates:
- bin/myapp
cmds:
- go build -o bin/myapp ./cmd/myapp
# MUST have caching: generation tasks
generate:
desc: Generate code from proto
sources:
- proto/**/*.proto
generates:
- gen/**/*.pb.go
cmds:
- protoc --go_out=gen/ proto/*.proto
# MUST have status: installation tasks
install-deps:
desc: Install dependencies
status:
- test -d node_modules
cmds:
- npm ci
```
## Exempt from Caching
```yaml
# OK without caching: quick/stateless tasks
dev:
desc: Start development server
cmds:
- npm run dev
clean:
desc: Remove artifacts
cmds:
- rm -rf bin/ dist/
deploy:
desc: Deploy (always run)
cmds:
- ./deploy.sh
```
## Caching Decision Table
| Task Type | Caching Method |
|-----------|---------------|
| Build/compile | sources + generates |
| Code generation | sources + generates |
| Lint/format | sources only |
| Install deps | status |
| Dev server | None (always run) |
| Clean | None (always run) |
| Deploy | None (always run) |
## Good
```yaml
build:
sources: ["**/*.go", "go.mod"]
generates: ["bin/app"]
cmds: ["go build -o bin/app"]
```
## Bad
```yaml
build:
cmds: ["go build -o bin/app"]
# No caching — rebuilds every time even if nothing changed
```