You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6366581
Browse filesBrowse the repository at this point in the historyBrowse files
Remote cache: fix write-back during hedged reads and a getParams edge case (#2251)
Summary:
Follow-ups from the react/metro review of the two remote cache changes (#2249, #2246).
**A hedged local transform no longer writes to a remote store that is about to hit.** `Cache.set` skips the store that served a hit and the stores after it, using `Cache.#hits`, which is only filled once a `get` returns. With `unstable_hedgeCacheReadsAfterMs`, the local transform can win while the remote read is still pending, so `set` wrote to every store: with a read-write remote (`HttpStore`), one redundant upload per file that already exists remotely, on the congested link the option is for. `HttpGetStore` does not write, so the setup this was built for was not affected.
`Cache` now tracks the store each pending `get` is reading. A `set` during that read writes the stores the read has already missed at once, and the rest when the read settles, stopping at the store that hit: the same stores a `set` after the read would write. On a miss everything is still written; nothing changes when no read is pending. The bookkeeping is one small object per `get`, and a promise only when a `set` overlaps it.
**`getParams` resolving to a plain object or nothing is a cache miss, not a build failure.** The parameters are now built with `new URLSearchParams(extra ?? undefined)` inside the guarded part, so a plain object such as `{token: 'abc'}` is used as parameters and `undefined`/`null` adds none, and anything else that fails becomes a `NetworkError`. Errors from the request itself are still not wrapped.
**Docs:** `Configuration.md` said racing transforms run at most `maxWorkers` at a time; they share `2 * maxWorkers` slots with cache-miss transforms. `Caching.md` describes the write order when a write overlaps a read.
Changelog: [Fix] metro-cache: a result written while a read of the same key is still under way no longer writes to the store that read then hits, and an `HttpStore` `getParams` that resolves to a plain object or nothing no longer fails the build
Differential Revision: D133210770
Copy file name to clipboardExpand all lines: docs/Caching.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ A typical setup involves:
17
17
2. Running [`metro build`](./CLI.md#build-entry) periodically (e.g. in a CI job) to populate the cache, using `HttpStore` (or a custom read/write cache store) in your Metro config.
18
18
3. Configuring Metro on development machines to read from the cache, using `HttpGetStore` (or a custom read-only cache store).
19
19
20
-
Caches are configured with [`cacheStores`](./Configuration.md#cachestores). Metro reads the stores in order and uses the first hit, then writes the result to every store listed before the one that hit (or to all of them, on a miss). So the local cache (e.g. `FileStore`) should usually come first, followed by the remote cache (e.g. `HttpStore` or `HttpGetStore`): a result found only remotely is then copied into the local cache for the next build. For example, on development machines:
20
+
Caches are configured with [`cacheStores`](./Configuration.md#cachestores). Metro reads the stores in order and uses the first hit, then writes the result to every store listed before the one that hit (or to all of them, on a miss). If a result is written while a read of the same key is still under way, the stores that read has already missed are written at once, and the rest once the read finishes, again stopping at the one that hit. So the local cache (e.g. `FileStore`) should usually come first, followed by the remote cache (e.g. `HttpStore` or `HttpGetStore`): a result found only remotely is then copied into the local cache for the next build. For example, on development machines:
Copy file name to clipboardExpand all lines: docs/Configuration.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -108,7 +108,7 @@ type JsonSerializable = /* Any JSON-serializable value */;
108
108
109
109
Type: `?number`
110
110
111
-
If a transform cache read has not returned after this many milliseconds, Metro also queues the transform locally and uses whichever result arrives first. Use it with a remote cache store, so that a slow or congested link can't make builds slower than transforming locally. Local transforms that race a cache read run newest first, at most [`maxWorkers`](#maxworkers)at a time, and are dropped if the cache answers before they start. Defaults to `null` (wait for the cache).
111
+
If a transform cache read has not returned after this many milliseconds, Metro also queues the transform locally and uses whichever result arrives first. Use it with a remote cache store, so that a slow or congested link can't make builds slower than transforming locally. Local transforms that race a cache read run newest first, sharing twice as many slots as [`maxWorkers`](#maxworkers)with the transforms of cache misses (which go first), and are dropped if the cache answers before they start. When a local transform wins, Metro writes its result to a later cache store only once that store's pending read has missed. Defaults to `null` (wait for the cache).
0 commit comments