docs/current_docs/extending/how-dagger-works/cache.mdx
Dagger cache follows the graph.
Same inputs, same work, same result: Dagger can reuse it.
Different inputs: Dagger reruns the affected work.
This is why module API design affects speed.
Precise inputs make precise cache keys.
Use narrow inputs:
Broad inputs make broad invalidation. If a lint function accepts the whole repo, a README change can rerun work that only needed source files.
Composable outputs help cache too.
Return a Container, Directory, File, or object when the caller may keep building. Let the caller decide when to materialize.
Materialize only when the function is meant to produce a final result.
Cache volumes are for tool caches:
They are not source of truth. A module must still be correct with an empty cache.
Local and CI caches are often separate. Dagger Cloud can share cache across environments.
Do not depend on a warm cache. Design for correctness first, speed second.
Ask:
Directory or File?Next: Execution.