What Should You Really Cache in a CI/CD Pipeline?
Posted on March 11, 2026 • 4 min read • 727 wordsAdding cache to a CI/CD pipeline is not about storing random files. This article offers a pragmatic framework to understand what to cache, why it matters, and how to avoid a fragile or counterproductive cache.

When trying to speed up a CI/CD pipeline, the first idea that almost always comes up is:
“we need to add cache”
But very quickly, another question appears:
what exactly are we caching?
Files? Folders? Docker images? Dependencies?
And above all: which cache has a real impact, and which one just makes the system more complex?
This article offers a simple and pragmatic framework for answering that question.
Many pipelines start like this:
node_modules.pnpm-store or .npmThe result:
The problem is not caching itself.
The problem is what we are trying to cache.
A CI/CD pipeline is not a sequence of files, it is a sequence of tasks:
Every useful cache corresponds to a well-defined task, with:
If the inputs have not changed, the work does not need to be done again.
That is the logic that should guide any effective caching strategy.
It avoids downloading again what already exists. This should be done almost all the time.
Examples:
Value
Limitation
This is an excellent candidate, often overlooked, and yet highly valuable.
Examples:
Value
Key condition
This is where things become interesting… and delicate.
Examples:
Value
Risk
Good practice
It is very useful, but it requires discipline.
Often counterintuitive, but sometimes relevant. It should be used carefully.
Examples:
Value
Caution
Docker cache is linear. It is excellent for packaging, but poor as the main cache for application logic:
What Docker caches well
What Docker cannot do
An effective pipeline caches:
| Type of work | Recommended cache |
|---|---|
| Downloading | Yes |
| Code generation | Yes |
| Per-project build | Yes |
| Deterministic tests | Sometimes |
| Docker images | Yes (but not alone) |
Most importantly: each cache should correspond to an explicit task, not an arbitrary folder.
Because they stack:
Without ever answering the fundamental question:
What work am I trying to avoid doing again?
When that answer is not clear, the cache becomes:
A good CI/CD cache has one simple property:
A developer can predict what will be reused without reading the CI configuration.
If that is not the case, the cache is too implicit.
Adding cache to a CI/CD pipeline is not a tooling question.
It is a matter of modeling work.
The tools come after that. Always.