cache

The cache command is used to store or restore cache in CI jobs. Caching dependencies can save the time taken to install the dependencies in subsequent CI Jobs. To make use of this feature you need to add the cache store and cache restore commands to your workflow.

  • The cache store command is used to store your dependencies in cache.

  • The cache restore command restores the cache that was already stored.

Example

- cache restore
- bundle install --jobs 1
- yarn install
- cache store

In the example given above, the cache restore and cache store commands are added before and after the installation commands. Here's what will happen when these commands are first executed:

  1. The cache restore command does nothing in the first CI job run since a cache has not been created yet.

  2. The bundle install --jobs 1 and yarn install commands installs all the dependencies.

  3. The cache store command creates a cache of all the installed dependencies.

Screenshot 2024-10-25 at 12.02.47.png

And here's what will happen in subsequent CI jobs:

  1. The cache restore command restores the cached dependencies that were cached in the previous CI Job run.

  2. The bundle install --jobs 1 and yarn install commands are run, but the cached packages do not need to be installed again. Hence this operation will be completed faster.

  3. The cache store command does not do anything if there are no changes to the dependencies. If there are changes made to the dependencies, cache store updates the changes in the cache.

Screenshot 2024-10-25 at 12.05.40.png

In the screenshots given above, you can see that there is a significant reduction in the time taken for the completion of the CI Jobs.

We recommend adding the cache commands in the same order as shown in the example given above. It ensures that the cache is restored before any installation and also ensures that any changes made to the dependencies are reflected on the cache.

Can't find what you're looking for?