远程缓存
Turborepo 的 任务缓存 通过避免重复执行相同的工作来节省时间。
¥Turborepo's task cache saves time by never doing the same work twice.
但有一个问题:缓存位于你的计算机本地。当你使用持续集成系统时,这可能会导致大量重复工作:
¥But there's a problem: the cache is local to your machine. When you're working with a Continuous Integration system, this can result in a lot of duplicated work:


由于 Turborepo 默认仅缓存到本地文件系统,因此即使所有任务输入都相同,也必须在每台机器上(由你、你的团队成员、你的 CI、你的 PaaS 等)重新执行相同的任务 (turbo run build
) - 这会浪费时间和资源。
¥Since Turborepo only caches to the local filesystem by default, the same task (turbo run build
) must be re-executed on each machine (by you, by your teammates, by your CI, by your PaaS, etc.) even when all of the task inputs are identical — which wastes time and resources.
Good to know:
使用 Turborepo 无需使用远程缓存。虽然远程缓存将带来最显著的加速,但你也可以在没有远程缓存的情况下加快现有工作流程的速度。
¥You don't have to use Remote Caching to use Turborepo. While Remote Caching will bring the most significant speedups, you can make your existing workflows faster without Remote Caching, too.
单一共享缓存
¥A single, shared cache
如果你可以在整个团队(甚至你的持续集成 (CI))之间共享一个 Turborepo 缓存会怎么样?
¥What if you could share a single Turborepo cache across your entire team (and even your CI)?


Turborepo 可以与远程缓存进行安全通信 - 一个云服务器,用于存储你的任务结果。这可以避免整个组织中的重复工作,从而节省大量时间。
¥Turborepo can securely communicate with a remote cache - a cloud server that stores the results of your tasks. This can save enormous amounts of time by preventing duplicated work across your entire organization.
远程缓存是免费的,可以与 托管提供程序 一起使用,也可以作为 自托管缓存 使用。
¥Remote Caching is free and can be used with both managed providers or as a self-hosted cache.
远程缓存是 Turborepo 的一项强大功能,但功能强大,责任重大。首先确保缓存正确,并仔细检查 环境处理变量。另请记住,Turborepo 将日志视为工件,因此请注意打印到控制台的内容。
¥Remote Caching is a powerful feature of Turborepo, but, with great power, comes great responsibility. Make sure you are caching correctly first and double check handling of environment variables. Please also remember Turborepo treats logs as artifacts, so be aware of what you are printing to the console.
Vercel
即使你的应用不在 Vercel 上托管,Vercel 远程缓存 在所有计划中均可免费使用。按照以下步骤为你的仓库启用远程缓存。
¥Vercel Remote Cache is free to use on all plans, even if you do not host your applications on Vercel. Follow the steps below to enable Remote Caching for your repository.
用于本地开发
¥For Local Development
要将本地 Turborepo 链接到远程缓存,请使用你的 Vercel 账户验证 Turborepo CLI:
¥To link your local Turborepo to your Remote Cache, authenticate the Turborepo CLI with your Vercel account:
如果你尚未安装 全局 turbo
,也可以使用包管理器:
¥You can also use your package manager if you do not have global turbo
installed:
如果你的远程缓存配置为使用单点登录,则需要运行 npx turbo login --sso-team=team-name
才能获取具有正确权限的缓存令牌。
¥If your Remote Cache is configured to use single-sign-on you will need to run
npx turbo login --sso-team=team-name
in order to get a cache token with the
correct privileges.
现在,将你的 Turborepo 链接到你的远程缓存:
¥Now, link your Turborepo to your Remote Cache:
启用后,对当前缓存的包进行一些更改,并使用 turbo run
针对其运行任务。你的缓存工件现在将存储在本地和远程缓存中。
¥Once enabled, make some changes to a package you are currently caching and run tasks against it with turbo run
.
Your cache artifacts will now be stored locally and in your Remote Cache.
要验证,请使用以下命令删除本地 Turborepo 缓存:
¥To verify, delete your local Turborepo cache with:
然后,再次运行相同的构建。如果一切正常,turbo
不应在本地执行任务。相反,它会从你的远程缓存下载日志和工件,并将它们重放给你。
¥Then, run the same build again. If things are working properly, turbo
should not execute tasks locally. Instead, it will download the logs and artifacts from your Remote Cache and replay them back to you.
Vercel 上的远程缓存
¥Remote Caching on Vercel
如果你在 Vercel 上构建和托管应用,则一旦你使用 turbo
,远程缓存将自动为你设置。更多信息请参阅 Vercel 文档。
¥If you are building and hosting your apps on Vercel, Remote Caching will be automatically set up on your behalf once you use turbo
. Refer to the Vercel documentation for more information.
工件完整性和真实性验证
¥Artifact Integrity and Authenticity Verification
Turborepo 可以在将工件上传到远程缓存之前使用密钥对其进行签名。Turborepo 使用你提供的密钥对工件进行 HMAC-SHA256
签名。Turborepo 将验证已下载的远程缓存工件。任何验证失败的工件都将被 Turborepo 忽略并视为缓存未命中。
¥Turborepo can sign artifacts with a secret key before uploading them to the Remote Cache. Turborepo uses HMAC-SHA256
signatures on artifacts using a secret key you provide.
Turborepo will verify the Remote Cache artifacts' integrity and authenticity when they're downloaded.
Any artifacts that fail to verify will be ignored and treated as a cache miss by Turborepo.
要启用此功能,请在 turbo.json
配置中将 remoteCache
选项设置为包含 signature: true
。然后通过声明 TURBO_REMOTE_CACHE_SIGNATURE_KEY
环境变量来指定你的密钥。
¥To enable this feature, set the remoteCache
options on your turbo.json
config to include signature: true
. Then specify your secret key by declaring the TURBO_REMOTE_CACHE_SIGNATURE_KEY
environment variable.


远程缓存 API
¥Remote Cache API
任何符合 Turborepo 远程缓存 API 规范的 HTTP 服务器都可以实现远程缓存。
¥A Remote Cache can be implemented by any HTTP server that meets Turborepo's Remote Caching API specification.
使用 Vercel 管理远程缓存
¥Managed Remote Cache with Vercel
Vercel,Turborepo 的创建者和维护者,提供与 Turborepo 完全兼容的托管远程缓存。
¥Vercel, the creators and maintainers of Turborepo, provide a managed Remote Cache that is fully compatible with Turborepo.
使用 Vercel 远程缓存 无需配置,并通过开源 Vercel 远程缓存 SDK 自动与 Vercel 部署 集成。
¥Using Vercel Remote Cache is zero-configuration and automatically integrates with Vercel deployments through the open-source Vercel Remote Cache SDK.
了解有关 Vercel 上的 Turborepo 或 免费部署模板 的更多信息以试用。
¥Learn more about Turborepo on Vercel or deploy a template for free to try it out.
自托管
¥Self-hosting
你还可以自行托管自己的远程缓存,并使用 --manual
标志登录,提供 API URL、团队和令牌信息。
¥You can also self-host your own Remote Cache and log into it using the --manual
flag to provide API URL, team, and token information.
OpenAPI 规范
¥OpenAPI specification
目前,所有版本的 turbo
都与 v8
端点兼容。
¥At this time, all versions of turbo
are compatible with the v8
endpoints.
社区实现
¥Community implementations
Turborepo 社区已经创建了远程缓存的开源实现。
¥The Turborepo community has created open-source implementations of the Remote Cache.