| Keep rollin’ rollin’ rollin’ rollin’. — William Frederick Durst |

Azure DevOps provides a handy Cache task which can improve build performance by caching files between pipeline runs. The documentation has plenty if examples to get you started.
The save/restore mechanism is based on the “keys”, which are used to compute an unique hash based on strings and/or file contents. This works fine for dependencies, where you can target dependecy-describing file(s) and the task will update cache only if they change. For npm this would be package-lock.json, for NuGet — packages.lock.json and so on. You can also have “fallback” keys, where cache will be restored on partial match in hope that it can be at least partially re-used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example from Cache task documentation for npm | |
| variables: | |
| npm_config_cache: $(Pipeline.Workspace)/.npm | |
| steps: | |
| – task: Cache@2 | |
| inputs: | |
| key: 'npm | "$(Agent.OS)" | package-lock.json' | |
| restoreKeys: | | |
| npm | "$(Agent.OS)" | |
| path: $(npm_config_cache) | |
| displayName: Cache npm | |
| – script: npm ci |
But what if you need to cache build output and keep this cache fresh, updating it each time pipeline runs?






