Skip to content

Commit f90a780

Browse files
authored
Turbopack: rename turbopackPersistentCachingForXXX to turbopackFileSystemCacheForXXX (#84632)
### What? Improve naming of the feature: `Turbopack FileSystem Cache`
1 parent a7d3aec commit f90a780

File tree

73 files changed

+282
-287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+282
-287
lines changed

bench/heavy-npm-deps/next.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const nextConfig = {
77
ignoreBuildErrors: true,
88
},
99
experimental: {
10-
turbopackPersistentCachingForDev: process.env.TURBO_CACHE === '1',
11-
turbopackPersistentCachingForBuild: process.env.TURBO_CACHE === '1',
10+
turbopackFileSystemCacheForDev: process.env.TURBO_CACHE === '1',
11+
turbopackFileSystemCacheForBuild: process.env.TURBO_CACHE === '1',
1212
},
1313
}
1414

crates/napi/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn main() -> anyhow::Result<()> {
3333
let cargo = vergen_gitcl::CargoBuilder::default()
3434
.target_triple(true)
3535
.build()?;
36-
// We use the git dirty state to disable persistent caching (persistent caching relies on a
36+
// We use the git dirty state to disable filesystem cache (filesystem cache relies on a
3737
// commit hash to be safe). One tradeoff of this is that we must invalidate the rust build more
3838
// often.
3939
//
@@ -46,7 +46,7 @@ fn main() -> anyhow::Result<()> {
4646
//
4747
// However, in practice that shouldn't be much of an issue: If no other dependency of this
4848
// top-level crate has changed (which would've triggered our rebuild), then the resulting binary
49-
// must be equivalent to a clean build anyways. Therefore, persistent caching using the HEAD
49+
// must be equivalent to a clean build anyways. Therefore, filesystem cache using the HEAD
5050
// commit hash as a version is okay.
5151
let git = vergen_gitcl::GitclBuilder::default()
5252
.dirty(/* include_untracked */ true)

crates/napi/src/next_api/project.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub struct NapiDefineEnv {
238238

239239
#[napi(object)]
240240
pub struct NapiTurboEngineOptions {
241-
/// Use the new backend with persistent caching enabled.
241+
/// Use the new backend with filesystem cache enabled.
242242
pub persistent_caching: Option<bool>,
243243
/// An upper bound of memory that turbopack will attempt to stay under.
244244
pub memory_limit: Option<f64>,
@@ -602,10 +602,10 @@ pub async fn project_update(
602602
.await
603603
}
604604

605-
/// Invalidates the persistent cache so that it will be deleted next time that a turbopack project
606-
/// is created with persistent caching enabled.
605+
/// Invalidates the filesystem cache so that it will be deleted next time that a turbopack project
606+
/// is created with filesystem cache enabled.
607607
#[napi]
608-
pub async fn project_invalidate_persistent_cache(
608+
pub async fn project_invalidate_file_system_cache(
609609
#[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
610610
) -> napi::Result<()> {
611611
tokio::task::spawn_blocking(move || {
@@ -619,7 +619,7 @@ pub async fn project_invalidate_persistent_cache(
619619
.invalidate(invalidation_reasons::USER_REQUEST)
620620
})
621621
.await
622-
.context("panicked while invalidating persistent cache")??;
622+
.context("panicked while invalidating filesystem cache")??;
623623
Ok(())
624624
}
625625

crates/napi/src/next_api/turbopack_ctx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl CompilationEvent for StartupCacheInvalidationEvent {
250250
_ => "", // ignore unknown reasons
251251
};
252252
format!(
253-
"Turbopack's persistent cache has been deleted{reason_msg}. Builds or page loads may \
253+
"Turbopack's filesystem cache has been deleted{reason_msg}. Builds or page loads may \
254254
be slower as a result."
255255
)
256256
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Turbopack FileSystem Caching
3+
nav_title: turbopackFileSystemCache
4+
description: Learn how to enable FileSystem Caching for Turbopack builds
5+
version: canary
6+
---
7+
8+
## Usage
9+
10+
Turbopack FileSystem Cache enables Turbopack to reduce work across `next dev` or `next build` commands. When enabled, Turbopack will save and restore data to the `.next` folder between builds, which can greatly speed up subsequent builds and dev sessions.
11+
12+
> **Warning:** FileSystem Cache is still under development and is not yet stable. Users adopting should expect some stability issues.
13+
14+
> **Good to know**: Note that while `next dev` and `next build` can share cached data with each other, most cache entries are command-specific due to different configuration and environment variables.
15+
16+
```ts filename="next.config.ts" switcher
17+
import type { NextConfig } from 'next'
18+
19+
const nextConfig: NextConfig = {
20+
experimental: {
21+
// Enable filesystem caching for `next dev`
22+
turbopackFileSystemCacheForDev: true,
23+
// Enable filesystem caching for `next build`
24+
turbopackFileSystemCacheForBuild: true,
25+
},
26+
}
27+
28+
export default nextConfig
29+
```
30+
31+
```js filename="next.config.js" switcher
32+
/** @type {import('next').NextConfig} */
33+
const nextConfig = {
34+
experimental: {
35+
// Enable filesystem caching for `next dev`
36+
turbopackFileSystemCacheForDev: true,
37+
// Enable filesystem caching for `next build`
38+
turbopackFileSystemCacheForBuild: true,
39+
},
40+
}
41+
42+
module.exports = nextConfig
43+
```
44+
45+
## Version Changes
46+
47+
| Version | Changes |
48+
| --------- | ------------------------------------------- |
49+
| `v16.0.0` | Separate flags for build and dev. |
50+
| `v15.5.0` | Persistent caching released as experimental |

docs/01-app/03-api-reference/05-config/01-next-config-js/turbopackPersistentCaching.mdx

Lines changed: 0 additions & 50 deletions
This file was deleted.

docs/01-app/03-api-reference/08-turbopack.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ We are planning to offer an equivalent to the `innerGraph` optimization in Turbo
140140

141141
### Build Caching
142142

143-
Webpack supports [disk build caching](https://webpack.js.org/configuration/cache/#cache) to speed up builds. We are planning to support an analogous feature in Turbopack but it is not ready yet. On the `next@canary` release you can experiment with our solution by enabling the [`experimental.turbopackPersistentCachingForDev`/`experimental.turbopackPersistentCachingForBuild` flags](/docs/app/api-reference/config/next-config-js/turbopackPersistentCaching).
143+
Webpack supports [disk build caching](https://webpack.js.org/configuration/cache/#cache) to speed up builds. We are planning to support an analogous feature in Turbopack but it is not ready yet. On the `next@canary` release you can experiment with our solution by enabling the [`experimental.turbopackFileSystemCacheForDev`/`experimental.turbopackFileSystemCacheForBuild` flags](/docs/app/api-reference/config/next-config-js/turbopackFileSystemCache).
144144

145145
> **Good to know:** For this reason, when comparing webpack and Turbopack performance, make sure to delete the `.next` folder between builds to see a fair comparison.
146146

errors/no-cache.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: No Cache Detected
66

77
A Next.js build was triggered in a continuous integration environment, but no cache was detected.
88

9-
This results in slower builds and can hurt Next.js' persistent caching of client-side bundles across builds.
9+
This results in slower builds and can hurt Next.js' filesystem cache of client-side bundles across builds.
1010

1111
## Possible Ways to Fix It
1212

packages/next/src/build/define-env.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,19 +320,19 @@ export function getDefineEnv({
320320

321321
// The devtools need to know whether or not to show an option to clear the
322322
// bundler cache. This option may be removed later once Turbopack's
323-
// persistent cache feature is more stable.
323+
// filesystem cache feature is more stable.
324324
//
325325
// This environment value is currently best-effort:
326326
// - It's possible to disable the webpack filesystem cache, but it's
327327
// unlikely for a user to do that.
328-
// - Rspack's persistent cache is unstable and requires a different
328+
// - Rspack's filesystem cache is unstable and requires a different
329329
// configuration than webpack to enable (which we don't do).
330330
//
331331
// In the worst case we'll show an option to clear the cache, but it'll be a
332332
// no-op that just restarts the development server.
333333
'process.env.__NEXT_BUNDLER_HAS_PERSISTENT_CACHE':
334334
!isTurbopack ||
335-
(config.experimental.turbopackPersistentCachingForDev ?? false),
335+
(config.experimental.turbopackFileSystemCacheForDev ?? false),
336336
'process.env.__NEXT_REACT_DEBUG_CHANNEL':
337337
config.experimental.reactDebugChannel ?? false,
338338
}

packages/next/src/build/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ import {
206206
} from '../server/lib/router-utils/build-prefetch-segment-data-route'
207207

208208
import { turbopackBuild } from './turbopack-build'
209-
import { isPersistentCachingEnabledForBuild } from '../shared/lib/turbopack/utils'
209+
import { isFileSystemCacheEnabledForBuild } from '../shared/lib/turbopack/utils'
210210
import { inlineStaticEnv } from '../lib/inline-static-env'
211211
import { populateStaticEnv } from '../lib/static-env'
212212
import { durationToString, hrtimeDurationToString } from './duration-to-string'
@@ -2728,8 +2728,8 @@ export default async function build(
27282728
invocationCount: config.experimental.ppr ? 1 : 0,
27292729
},
27302730
{
2731-
featureName: 'turbopackPersistentCaching',
2732-
invocationCount: isPersistentCachingEnabledForBuild(config) ? 1 : 0,
2731+
featureName: 'turbopackFileSystemCache',
2732+
invocationCount: isFileSystemCacheEnabledForBuild(config) ? 1 : 0,
27332733
},
27342734
]
27352735
telemetry.record(

0 commit comments

Comments
 (0)