Skip to content

Commit fe7b129

Browse files
committed
chore(doc): document the effect of ?write=true on caching
PR-URL: #19 Credit: @isaacs Close: #19 Reviewed-by: @isaacs
1 parent ba8b4fe commit fe7b129

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ Happy hacking!
5050

5151
### API
5252

53+
#### Caching and `write=true` query strings
54+
55+
Before performing any PUT or DELETE operation, npm clients first make a
56+
GET request to the registry resource being updated, which includes
57+
the query string `?write=true`.
58+
59+
The semantics of this are, effectively, "I intend to write to this thing,
60+
and need to know the latest current value, so that my write can land
61+
cleanly".
62+
63+
The public npm registry handles these `?write=true` requests by ensuring
64+
that the cache is re-validated before sending a response. In order to
65+
maintain the same behavior on the client, and not get tripped up by an
66+
overeager local cache when we intend to write data to the registry, any
67+
request that comes through `npm-registry-fetch` that contains `write=true`
68+
in the query string will forcibly set the `prefer-online` option to `true`,
69+
and set both `prefer-offline` and `offline` to false, so that any local
70+
cached value will be revalidated.
71+
5372
#### <a name="fetch"></a> `> fetch(url, [opts]) -> Promise<Response>`
5473

5574
Performs a request to a given URL.
@@ -391,6 +410,9 @@ Force offline mode: no network requests will be done during install. To allow
391410
This option is only really useful if you're also using
392411
[`opts.cache`](#opts-cache).
393412

413+
This option is set to `true` when the request includes `write=true` in the
414+
query string.
415+
394416
##### <a name="opts-otp"></a> `opts.otp`
395417

396418
* Type: Number | String
@@ -402,7 +424,7 @@ account.
402424

403425
##### <a name="opts-password"></a> `opts.password`
404426

405-
* Alias: _password
427+
* Alias: `_password`
406428
* Type: String
407429
* Default: null
408430

@@ -432,6 +454,9 @@ will be requested from the server. To force full offline mode, use
432454
This option is generally only useful if you're also using
433455
[`opts.cache`](#opts-cache).
434456

457+
This option is set to `false` when the request includes `write=true` in the
458+
query string.
459+
435460
##### <a name="opts-prefer-online"></a> `opts.prefer-online`
436461

437462
* Type: Boolean
@@ -443,6 +468,8 @@ for updates immediately even for fresh package data.
443468
This option is generally only useful if you're also using
444469
[`opts.cache`](#opts-cache).
445470

471+
This option is set to `true` when the request includes `write=true` in the
472+
query string.
446473

447474
##### <a name="opts-project-scope"></a> `opts.project-scope`
448475

@@ -606,4 +633,4 @@ See also [`opts.password`](#opts-password)
606633
* Default: null
607634

608635
** DEPRECATED ** This is a legacy authentication token supported only for
609-
*compatibility. Please use [`opts.token`](#opts-token) instead.
636+
compatibility. Please use [`opts.token`](#opts-token) instead.

0 commit comments

Comments
 (0)