Distributed Caching

Only Build, Test, Lint Once

When running Nx without Nx Cloud, a computation cache is created on your local machine to make the developer experience faster. This allows you to not waste time re-building, re-testing, re-linting, or any number of other actions you might take on code that hasn’t changed. Since the cache is stored locally, you are the only member of your team that can take advantage of these instant commands.

Nx Cloud allows this cache to be shared across your entire organization, meaning that any cacheable operation completed on your workspace only needs to be run once.

The time savings that this can provide your team are drastic. This blog post explains how such a simple concept can have a massive impact on productive time for you and your team.

Enabling Cache

To enable the cache:

  1. Connect your workspace to Nx Cloud

  2. Make sure the cacheableOperations array in nx.json contains all the targets you want to cache.

  3. Make sure you configure an Nx Cloud access token.

If you configure a read-write access token in nx.json or via the NX_CLOUD_ACCESS_TOKEN env variable, any time you run a command the Nx CLI will upload the artifacts to the cloud.

If you configure the read-only access token, the Nx CLI will try to download cached artifacts from the Nx Cloud, but won't try to store them.

It's common to use a single read-write access token for small workspaces, and the combination of a read-write token for CI and a read-only token for local development for large workspaces.

See the Configuring the Cloud Runner section for more information on how to configure and troubleshoot the cache.

Testing Caching

To make sure the cache is on:

  1. Run a cacheable command (e.g., nx build yourappname). If you click on the Nx Cloud link, you will see that the task was a cache miss.

  2. Rerun the same command. If you click on the link again, you will see that the task was a local cache hit.

  3. Delete your local cache. By default, it's located in node_modules/.cache. After deleting, rerun the same command again. This time, if you click on the Nx Cloud link, you will see an icon of a cloud next to the task, indicating that the artifacts have been fetched from the cloud.

Select an article to learn more about Nx Cloud