Rebuilding and retesting the same code repeatedly is costly. Nx provides a computation caching system that ensures code is never rebuilt twice. It:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nrwl/nx/llms.txt
Use this file to discover all available pages before exploring further.
- Drastically speeds up local and CI task execution
- Saves money on CI/CD costs by skipping tasks that haven’t changed
- Restores both terminal output and output files (e.g. your
distdirectory)
Enable caching for tasks
Add"cache": true to any target in targetDefaults inside nx.json:
Cacheable tasks must be side-effect free — given the same inputs, they must always produce the same outputs. For example, e2e tests that hit a live backend API cannot be safely cached because the backend state can vary between runs.
View cache hits
When a cached result is replayed, Nx shows[local cache] next to the task in the terminal output:
Clear the cache
To clear the local cache and force all tasks to re-execute:.nx/cache by default.
Fine-tune caching with inputs and outputs
Nx caches tasks based on a hash of their inputs. You can control exactly what’s included:- Inputs — files, environment variables, and other values included in the hash
- Outputs — folders where task artifacts are written
- Globally (nx.json)
- Per project (project.json)
- Per project (package.json)
*.md files are excluded from the input hash so that changing a README does not invalidate the build cache.
Configure caching automatically with plugins
When you use Nx plugins, caching is often configured automatically. For example, adding@nx/vite detects your vite.config.ts and configures the build target’s cache settings — including inputs and outputs — without any manual configuration:
Enable remote caching
Local caching only helps on a single machine. The largest gains come from remote caching, which shares the cache across all developers and CI runs. Connect your workspace to Nx Cloud to enable remote caching (Nx Replay):30–70% faster CI
Teams report significantly faster CI pipelines after enabling remote caching, as tasks completed on one machine are replayed instantly on others.
Secure by default
Cache entries are immutable and access is controlled via tokens. End-to-end encryption is available for organizations with strict compliance requirements.
Troubleshoot caching
Tasks are not being cached
Tasks are not being cached
Confirm
"cache": true is set in targetDefaults for the relevant target in nx.json. If you’re using plugins, run nx show project <name> --web to check inferred configuration.Cache hits are not being restored
Cache hits are not being restored
Your inputs or outputs may be misconfigured. If a task reads files not listed in
inputs, or writes outside its declared outputs, cache restores will be incomplete. See the debug cache misses guide for details.Skip the cache for a single run
Skip the cache for a single run
Pass
--skip-nx-cache to bypass caching for a specific invocation:Change the cache location
Change the cache location
The local cache defaults to
.nx/cache. You can override this with the NX_CACHE_DIRECTORY environment variable or via nx.json configuration.