Enable Remote Caching in Vercel

Share this video with your friends

Social Share Links

Send Tweet

Remote caching is key when coworking on a project. Using Turborepo, you can upload your cache to the cloud and use it everywhere else. For example, if your coworker switches to your branch and runs the build, they can have your most recent cache saving them time.

We will start off by logging into Vercel and Turborepo then linking our Turborepo account to our Vercel account. Once that is done, we run npx turbo link to connect to our remote cache. Then in our Vercel dashboard, we will need to do some configuring to finish it up.

[0:00] Instructor : We already know that Turborepo stores its cache inside node_modules/.cache/turbo. One of the big advantages of Turborepo is that it provides remote caching. This means that you can upload your cache to the cloud and then use it everywhere else. [0:24] For instance, if you have a teammate that is working on the same repository. Let's say that your teammate pulls your branch to check it out locally. Then, your teammate wants to run npx turbo run build. Your teammate won't have the cached version of the build pipeline locally.

[0:49] If you are using remote caching, when your teammate runs npx turbo run build, it will fetch the cached version from the cloud. It will be super quick.

[1:03] To enable remote caching, we have to type npx turbo login. It opens a new browser in vercel.com asking for permissions to authorize the Turborepo CLI. We accept. We have to go back to the terminal. It says that we connected our Turborepo CLI with Vercel.

[1:29] Now, we have to run npx turbo link. Let's clear this up. Let's run that command, turbo link. It is asking me if I want to enable remote catching for my project. I type yes. It asks me to what account do I want to associate the remote caching with. In this case, this is the only account that I have. It is selected by default. I hit Enter. That's it. We have remote caching enabled.

[2:00] Now, let's run npx turbo run build. In your Vercel dashboard, you have to go to the Usage tab. Then, you can click in the Artifacts tab as well. You can find the time saved by Turborepo. You can find the number of remote cache artifacts.

[2:27] Here, we can see today, which is August 25, that we have uploaded three artifacts. You can also see other nice things like the size of the artifacts. For instance, what we just uploaded is around 9 MB.

[2:43] Now to see that remote caching is working, I'm going to delete the local cache and I'm going to run npx turbo run build. Even though this was not as fast as a local cache, because Turborepo had to download the artifacts, it said that we have three out of three cached. These are the ones that live in the cloud.

[3:14] Again, if you scroll all the way to the top, you'll see that it says remote computation caching enabled. When we try to run the utils build, it says cache hit, replaying output. The same applies for the other projects. For instance, dashboard build and block build.

[3:32] To recap, remote caching is a great tool that let you store all your artifacts in the cloud and you can connect it for free to Vercel by doing npx turbo login and then npx turbo link to connect your project with the remote caching in Vercel.

[3:51] In order to see the usage of your artifacts, you can go to the usage tab, then click on artifacts, and it will show you the time that you have saved, the number of remote cache artifacts, and the size of those artifacts.