Self-Host your Remote Cache

Nx offers different ways to enable self-hosted remote caching for your workspace that can be used starting with Nx version 19.8 and higher:

  • Using the official Nx packages that come with ready-to-use adapters for AWS S3, GCP, Azure, and more.
  • Build your own cache server by following the Nx Remote Caching OpenAPI spec.
Free managed remote cache with Nx Cloud

Note, you can get started for free with a fully managed remote caching powered by Nx Cloud. It comes with a generous Hobby plan that is enough for most small teams. Learn more here.

If you are an enterprise and data privacy and security is a concern, reach out for an Enterprise trial. It is fully SOC 2 type 1 and 2 compliant and comes with single-tenant, dedicated EU region hosting as well as on-premise.

Are you an OSS project? Nx Cloud is free for OSS. Reach out here.

Official Nx Self-Hosted Cache Packages

The official self-hosted cache packages are the easiest migration path if you've been using a community caching solution based on the old custom task runner API in the past. All of the packages are completely free but require an activation key. Getting a key is a fully automated and self-serving process that happens during the package installation.

The following remote cache adapters are available:

Why require an activation key? It simply helps us know and support our users. If you prefer not to provide this information, you can also build your own cache server.

Migrating From Custom Tasks Runners

You might have used Nx's now deprecated custom task runners API in the following scenarios:

  • to implement custom self-hosted caching: going forward, use the official self-hosted packages or alternatively build your own caching server
  • to inject custom behavior before and after running tasks in Nx: for that purpose, we've built a new API exposing dedicated pre and post hooks.

To learn more about migrating from custom task runners, please refer to this detailed guide.

Build Your Own Caching Server

Starting in Nx version 20.8, you can build your own caching server using the OpenAPI specification provided below. This allows you to create a custom remote cache server that fits your specific needs. The server is responsible for managing all aspects of the remote cache, including storage, retrieval, and authentication.

Implementation is left up to you, but the server must adhere to the OpenAPI specification provided below to ensure compatibility with Nx's caching mechanism. The endpoints described below involve the transfer of tar archives which are sent as binary data. It is important to note that the underlying format of that data is subject to change in future versions of Nx, but the OpenAPI specification should remain stable.

As long as your server adheres to the OpenAPI spec, you can implement it in any programming language or framework of your choice.

Open API Specification

Nx 20.8+
1{ 2 "openapi": "3.0.0", 3 "info": { 4 "title": "Nx custom remote cache specification.", 5 "description": "Nx is a build system, optimized for monorepos, with AI-powered architectural awareness and advanced CI capabilities.", 6 "version": "1.0.0" 7 }, 8 "paths": { 9 "/v1/cache/{hash}": { 10 "put": { 11 "description": "Upload a task output", 12 "operationId": "put", 13 "security": [ 14 { 15 "bearerToken": [] 16 } 17 ], 18 "responses": { 19 "202": { 20 "description": "Successfully uploaded the output" 21 }, 22 "401": { 23 "description": "Missing or invalid authentication token.", 24 "content": { 25 "text/plain": { 26 "schema": { 27 "type": "string", 28 "description": "Error message provided to the Nx CLI user" 29 } 30 } 31 } 32 }, 33 "403": { 34 "description": "Access forbidden. (e.g. read-only token used to write)", 35 "content": { 36 "text/plain": { 37 "schema": { 38 "type": "string", 39 "description": "Error message provided to the Nx CLI user" 40 } 41 } 42 } 43 }, 44 "409": { 45 "description": "Cannot override an existing record" 46 } 47 }, 48 "parameters": [ 49 { 50 "in": "header", 51 "description": "The file size in bytes", 52 "required": true, 53 "schema": { 54 "type": "number" 55 }, 56 "name": "Content-Length" 57 }, 58 { 59 "name": "hash", 60 "description": "The task hash corresponding to the uploaded task output", 61 "in": "path", 62 "required": true, 63 "schema": { 64 "type": "string" 65 } 66 } 67 ], 68 "requestBody": { 69 "content": { 70 "application/octet-stream": { 71 "schema": { 72 "type": "string", 73 "format": "binary" 74 } 75 } 76 } 77 } 78 }, 79 "get": { 80 "description": "Download a task output", 81 "operationId": "get", 82 "security": [ 83 { 84 "bearerToken": [] 85 } 86 ], 87 "responses": { 88 "200": { 89 "description": "Successfully retrieved cache artifact", 90 "content": { 91 "application/octet-stream": { 92 "schema": { 93 "type": "string", 94 "format": "binary", 95 "description": "An octet stream with the content." 96 } 97 } 98 } 99 }, 100 "403": { 101 "description": "Access forbidden", 102 "content": { 103 "text/plain": { 104 "schema": { 105 "type": "string", 106 "description": "Error message provided to the Nx CLI user" 107 } 108 } 109 } 110 }, 111 "404": { 112 "description": "The record was not found" 113 } 114 }, 115 "parameters": [ 116 { 117 "name": "hash", 118 "in": "path", 119 "required": true, 120 "schema": { 121 "type": "string" 122 } 123 } 124 ] 125 } 126 } 127 }, 128 "components": { 129 "securitySchemes": { 130 "bearerToken": { 131 "type": "http", 132 "description": "Auth mechanism", 133 "scheme": "bearer" 134 } 135 } 136 } 137} 138

Usage Notes

To use your custom caching server, you must set the NX_SELF_HOSTED_REMOTE_CACHE_SERVER environment variable. Additionally, the following environment variables also affect the behavior:

  • NX_SELF_HOSTED_REMOTE_CACHE_ACCESS_TOKEN: The authentication token to access the cache server.
  • NODE_TLS_REJECT_UNAUTHORIZED: Set to 0 to disable TLS certificate validation.

Why Switch to Nx Cloud

Nx Cloud is much more than just a remote caching solution; it provides a full platform for scaling monorepos on CI. It comes with: