跳至主要内容

共享缓存

Lerna 提供的计算缓存可以分布在多台机器上。您可以构建缓存的实现,也可以使用 Nx Cloud。Nx Cloud 是一款应用程序,它提供了一种快速且零配置的分布式缓存实现。对于开源项目和大多数闭源项目,它是完全免费的(在此处阅读更多信息)。

您可以通过运行以下命令将您的工作区连接到 Nx Cloud

npx nx connect-to-nx-cloud
终端输出
✔ Enable distributed caching to make your CI faster · Yes

> NX Generating @nrwl/nx-cloud:init

UPDATE nx.json

> NX Distributed caching via Nx Cloud has been enabled

In addition to the caching, Nx Cloud provides config-free distributed execution,
UI for viewing complex runs and GitHub integration. Learn more at https://nx.app

Your workspace is currently unclaimed. Run details from unclaimed workspaces can be viewed on cloud.nx.app by anyone
with the link. Claim your workspace at the following link to restrict access.

https://cloud.nx.app/orgs/workspace-setup?accessToken=YOURACCESSTOKEN

要查看远程缓存的实际操作,请运行

lerna run build --scope=header && nx reset && lerna run build --scope=header
终端输出
> lerna run build --scope=header

> [email protected] build
> rimraf dist && rollup --config

src/index.tsx → dist...
created dist in 786ms

—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

Lerna (powered by Nx) Successfully ran target build for project header (2s)

See logs and investigate cache misses at https://cloud.nx.app/runs/k0HDHACpL8


> NX Resetting the Nx workspace cache and stopping the Nx Daemon.

This might take a few minutes.


> NX Daemon Server - Stopped


> NX Successfully reset the Nx workspace.


> lerna run build --scope=header [remote cache]


> [email protected] build
> rimraf dist && rollup --config


src/index.tsx → dist...
created dist in 786ms

—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

Lerna (powered by Nx) Successfully ran target build for project header (664ms)

Nx read the output from the cache instead of running the command for 1 out of 1 tasks.

Nx Cloud made it possible to reuse header: https://nx.app/runs/P0X6ZGTkqZ

将您的工作区连接到您的 Nx Cloud 帐户

在您在工作区中启用 Nx Cloud 后,您将看到以下内容

>  NX   NOTE  Nx Cloud has been enabled

Your workspace is currently public. Anybody with code access
can view the workspace on nx.app.

You can connect the workspace to your Nx Cloud account at
https://nx.app/orgs/workspace-setup?accessToken=N2Y3NzcyO...
(You can do this later.)

点击此链接将工作区与您的 Nx Cloud 帐户关联。如果您没有 Nx Cloud 帐户,您可以当场创建一个。

在您声明您的工作区后,您将能够管理权限、创建访问令牌、设置计费等等。

您还将看到一个交互式教程,帮助您探索分布式缓存和 Nx Cloud 用户界面。

如果您丢失了此链接,您仍然可以将您的工作区连接到 Nx Cloud。转到 nx.app,创建一个帐户,并使用 nx.json 中的访问令牌连接您的工作区。

跳过云

类似于 --skip-nx-cache 将指示 Nx 不要使用缓存,传递 --no-cloud 将告诉 Nx 不要使用 Nx Cloud。