docs(core): improve caching feature page

This commit is contained in:
Juri 2024-07-29 01:17:09 +02:00 committed by Juri Strumpflohner
parent 2dadf98188
commit a73bbfa7bb
6 changed files with 170 additions and 69 deletions

View File

@ -1090,14 +1090,6 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Change Cache Location",
"path": "/recipes/running-tasks/change-cache-location",
"id": "change-cache-location",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Run Custom Commands",
"path": "/recipes/running-tasks/run-commands-executor",
@ -1145,6 +1137,22 @@
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Change Cache Location",
"path": "/recipes/running-tasks/change-cache-location",
"id": "change-cache-location",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Skip Task Caching",
"path": "/recipes/running-tasks/skipping-cache",
"id": "skipping-cache",
"isExternal": false,
"children": [],
"disableCollapsible": false
}
],
"disableCollapsible": false
@ -2080,14 +2088,6 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Change Cache Location",
"path": "/recipes/running-tasks/change-cache-location",
"id": "change-cache-location",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Run Custom Commands",
"path": "/recipes/running-tasks/run-commands-executor",
@ -2135,6 +2135,22 @@
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Change Cache Location",
"path": "/recipes/running-tasks/change-cache-location",
"id": "change-cache-location",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Skip Task Caching",
"path": "/recipes/running-tasks/skipping-cache",
"id": "skipping-cache",
"isExternal": false,
"children": [],
"disableCollapsible": false
}
],
"disableCollapsible": false
@ -2163,14 +2179,6 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Change Cache Location",
"path": "/recipes/running-tasks/change-cache-location",
"id": "change-cache-location",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Run Custom Commands",
"path": "/recipes/running-tasks/run-commands-executor",
@ -2219,6 +2227,22 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Change Cache Location",
"path": "/recipes/running-tasks/change-cache-location",
"id": "change-cache-location",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Skip Task Caching",
"path": "/recipes/running-tasks/skipping-cache",
"id": "skipping-cache",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Adopting Nx",
"path": "/recipes/adopting-nx",

View File

@ -1488,17 +1488,6 @@
"path": "/recipes/running-tasks/defining-task-pipeline",
"tags": ["run-tasks"]
},
{
"id": "change-cache-location",
"name": "Change Cache Location",
"description": "",
"mediaImage": "",
"file": "shared/recipes/running-tasks/change-cache-location",
"itemList": [],
"isExternal": false,
"path": "/recipes/running-tasks/change-cache-location",
"tags": []
},
{
"id": "run-commands-executor",
"name": "Run Custom Commands",
@ -1564,6 +1553,28 @@
"isExternal": false,
"path": "/recipes/running-tasks/reduce-repetitive-configuration",
"tags": []
},
{
"id": "change-cache-location",
"name": "Change Cache Location",
"description": "",
"mediaImage": "",
"file": "shared/recipes/running-tasks/change-cache-location",
"itemList": [],
"isExternal": false,
"path": "/recipes/running-tasks/change-cache-location",
"tags": []
},
{
"id": "skipping-cache",
"name": "Skip Task Caching",
"description": "",
"mediaImage": "",
"file": "shared/recipes/running-tasks/skipping-cache",
"itemList": [],
"isExternal": false,
"path": "/recipes/running-tasks/skipping-cache",
"tags": []
}
],
"isExternal": false,
@ -2843,17 +2854,6 @@
"path": "/recipes/running-tasks/defining-task-pipeline",
"tags": ["run-tasks"]
},
{
"id": "change-cache-location",
"name": "Change Cache Location",
"description": "",
"mediaImage": "",
"file": "shared/recipes/running-tasks/change-cache-location",
"itemList": [],
"isExternal": false,
"path": "/recipes/running-tasks/change-cache-location",
"tags": []
},
{
"id": "run-commands-executor",
"name": "Run Custom Commands",
@ -2919,6 +2919,28 @@
"isExternal": false,
"path": "/recipes/running-tasks/reduce-repetitive-configuration",
"tags": []
},
{
"id": "change-cache-location",
"name": "Change Cache Location",
"description": "",
"mediaImage": "",
"file": "shared/recipes/running-tasks/change-cache-location",
"itemList": [],
"isExternal": false,
"path": "/recipes/running-tasks/change-cache-location",
"tags": []
},
{
"id": "skipping-cache",
"name": "Skip Task Caching",
"description": "",
"mediaImage": "",
"file": "shared/recipes/running-tasks/skipping-cache",
"itemList": [],
"isExternal": false,
"path": "/recipes/running-tasks/skipping-cache",
"tags": []
}
],
"isExternal": false,
@ -2958,17 +2980,6 @@
"path": "/recipes/running-tasks/defining-task-pipeline",
"tags": ["run-tasks"]
},
"/recipes/running-tasks/change-cache-location": {
"id": "change-cache-location",
"name": "Change Cache Location",
"description": "",
"mediaImage": "",
"file": "shared/recipes/running-tasks/change-cache-location",
"itemList": [],
"isExternal": false,
"path": "/recipes/running-tasks/change-cache-location",
"tags": []
},
"/recipes/running-tasks/run-commands-executor": {
"id": "run-commands-executor",
"name": "Run Custom Commands",
@ -3035,6 +3046,28 @@
"path": "/recipes/running-tasks/reduce-repetitive-configuration",
"tags": []
},
"/recipes/running-tasks/change-cache-location": {
"id": "change-cache-location",
"name": "Change Cache Location",
"description": "",
"mediaImage": "",
"file": "shared/recipes/running-tasks/change-cache-location",
"itemList": [],
"isExternal": false,
"path": "/recipes/running-tasks/change-cache-location",
"tags": []
},
"/recipes/running-tasks/skipping-cache": {
"id": "skipping-cache",
"name": "Skip Task Caching",
"description": "",
"mediaImage": "",
"file": "shared/recipes/running-tasks/skipping-cache",
"itemList": [],
"isExternal": false,
"path": "/recipes/running-tasks/skipping-cache",
"tags": []
},
"/recipes/adopting-nx": {
"id": "adopting-nx",
"name": "Adopting Nx",

View File

@ -380,11 +380,6 @@
"tags": ["run-tasks"],
"file": "shared/recipes/running-tasks/defining-task-pipeline"
},
{
"name": "Change Cache Location",
"id": "change-cache-location",
"file": "shared/recipes/running-tasks/change-cache-location"
},
{
"name": "Run Custom Commands",
"id": "run-commands-executor",
@ -420,6 +415,16 @@
"id": "reduce-repetitive-configuration",
"tags": [],
"file": "shared/recipes/running-tasks/reduce-repetitive-configuration"
},
{
"name": "Change Cache Location",
"id": "change-cache-location",
"file": "shared/recipes/running-tasks/change-cache-location"
},
{
"name": "Skip Task Caching",
"id": "skipping-cache",
"file": "shared/recipes/running-tasks/skipping-cache"
}
]
},

View File

@ -1,9 +1,11 @@
# Cache Task Results
It's costly to rebuild and retest the same code over and over again. Nx has the most sophisticated and battle-tested computation caching system to make sure it never rebuilds the same code twice. It knows when the task you are about to run, has been executed before, so it can use the cache to restore the results of running that task.
Rebuilding and retesting the same code repeatedly is costly. Nx offers a sophisticated and battle-tested computation caching system that ensures **code is never rebuilt twice**.
If you want to learn more about the conceptual model behind Nx's caching, read [How Caching Works](/concepts/how-caching-works).
## What gets cached?
## Define Cacheable Tasks
{% tabs %}
@ -51,14 +53,14 @@ the same output. As an example, e2e test runs that hit the backend API cannot be
the result of the test run.
{% /callout %}
Now, if you run a `build` task twice, the second time the operation will be instant because it is restored from the cache.
Now, if you run a `build` task twice, the operation will be instant the second time because it is restored from the cache.
{% terminal-video src="/documentation/shared/images/caching/cache-terminal-animation.mp4" alt="Video showing the terminal output of running a build command first without cache and then with cache. The 2nd run is almost instant, taking just 18ms" /%}
Nx restores both
- the terminal output
- the files & artifacts created as a result of running the task (e.g. your `build` or `dist` directory)
- The files and artifacts created from running the task (e.g., your `build` or `dist` directory)"
Keep reading to learn how to fine-tune what gets cached.
@ -124,19 +126,32 @@ The cache is stored in `.nx/cache` by default. You can also [change where the ca
## Enable Remote Caching
You can enable remote caching (Nx Replay) by connecting to [Nx Cloud](/ci/features/remote-cache). To connect Nx to Nx Cloud, [create an account on cloud.nx.app](https://cloud.nx.app) and connect to your repository.
Enable remote caching by connecting to [Nx Cloud](/nx-cloud):
```shell
npx nx connect
```
Learn more about [remote caching](/ci/features/remote-cache).
## Troubleshooting Caching
- debug cache misses
- [turn off or skip the cache](/recipes/running-tasks/skipping-cache)
- [change the cache location](/recipes/running-tasks/change-cache-location)
- clear the local or remote cache
---
## Turn off or Skip the Cache
If you want to ignore the cache (both reads and writes), use the `--skip-nx-cache` flag:
To ignore the cache (both reads and writes), use the `--skip-nx-cache` flag:
```shell
nx build header --skip-nx-cache
```
Alternatively if you want to disable caching for a particular task, just make sure it is not part [of the cached tasks](/features/cache-task-results#define-cacheable-tasks). If [you're using Nx Cloud](/ci/features/remote-cache#skipping-cloud-cache), you might want to use `--no-cloud` to skip remote caching.
Alternatively, to disable caching for a specific task, ensure it is not part of the [cached tasks](/features/cache-task-results#define-cacheable-tasks). If [you're using Nx Cloud](/ci/features/remote-cache#skipping-cloud-cache), you can use `--no-cloud` to skip remote caching.
## Clear the Local Cache

View File

@ -0,0 +1,23 @@
# Skip Task Caching
There are times when you might want to bypass the [caching mechanism](/features/cache-task-results), either locally or remotely.
## Skip Caching
To skip caching for a specific task, use the `--skip-nx-cache` flag. This can be useful when you want to ensure that a task runs fresh, without using cached results.
```shell
npx nx build --skip-nx-cache
```
This will avoid using any local or remote cache.
## Skip Remote Caching from Nx Cloud
To skip remote caching provided by Nx Cloud, use the `--no-cloud` flag. This ensures that the task does not use cached results from Nx Cloud.
```shell
npx nx build --no-cloud
```
It will **still use the local cache if available**.

View File

@ -55,13 +55,14 @@
- [Configure Inputs for Task Caching](/recipes/running-tasks/configure-inputs)
- [Configure Outputs for Task Caching](/recipes/running-tasks/configure-outputs)
- [Define a Task Pipeline](/recipes/running-tasks/defining-task-pipeline)
- [Change Cache Location](/recipes/running-tasks/change-cache-location)
- [Run Custom Commands](/recipes/running-tasks/run-commands-executor)
- [Pass Args to Commands](/recipes/running-tasks/pass-args-to-commands)
- [Run Tasks in Parallel](/recipes/running-tasks/run-tasks-in-parallel)
- [Run Root-Level NPM Scripts with Nx](/recipes/running-tasks/root-level-scripts)
- [Workspace Watching](/recipes/running-tasks/workspace-watching)
- [Reduce Repetitive Configuration](/recipes/running-tasks/reduce-repetitive-configuration)
- [Change Cache Location](/recipes/running-tasks/change-cache-location)
- [Skip Task Caching](/recipes/running-tasks/skipping-cache)
- [Adopting Nx](/recipes/adopting-nx)
- [NPM/Yarn/PNPM workspaces](/recipes/adopting-nx/adding-to-monorepo)
- [Migrate From Turborepo](/recipes/adopting-nx/from-turborepo)