Caching

Mint automatically provides content-based caching. If you run the same command on the same set of files, Mint will produce a cache hit rather than executing the task again. When using with filtering, you can ensure that your Mint runs are only executing the tasks which are necessary, based on the changes.

Content-based caching example

The cache key for each task is evaluated based on its inputs, regardless of whether upstream tasks are cache misses or cache hits. This means that Mint can produce a cache hit, even if one of its dependencies is a cache miss.

For example, let's start with this run definition:

tasks:
  - key: write-foo-txt
    run: echo foo > foo.txt

  - key: hash-foo-txt
    use: write-foo-txt
    run: sha256sum foo.txt

The write-foo-txt task will write foo to foo.txt. The hash-foo-txt task will calculate the sha256 hash of foo.txt.

Now, let's change the definition of the write-foo-txt task:

tasks:
  - key: write-foo-txt
    run: |
      echo foo > foo.txt
      echo finished writing foo.txt

  - key: hash-foo-txt
    use: write-foo-txt
    run: sha256sum foo.txt

The run command for write-foo-txt has changed, so it will be a cache miss and Mint will have to execute it. However, the input into hash-foo-txt is the same. Both the first and second implementations of write-foo-txt result in foo being written to foo.txt, even though the commands and log output will be different.

When Mint goes to run hash-foo-txt, it will notice that it's already run sha256sum foo.txt on a foo.txt file which contains foo, and therefore it will produce a cache hit.

Determinism

Mint does not currently do anything to detect whether commands are deterministic. If you run a command which is non-deterministic, such as using the date command, Mint will still cache it. You may need to be mindful of this if you want tasks to re-execute.

Incremental updates

Mint's content-based caching means that a task must be re-run if any input to it changed. Running a task from scratch can be undesirable if the task is amenable to incremental updates, for example if it is a dependency installation task like npm install or bundle install. Tool caches help with incremental updates.