Skip to content

Commit 1770f1b

Browse files
committedFeb 14, 2020
chore(doc): document the effect of ?write=true on caching
PR-URL: #18 Credit: @isaacs Close: #18 Reviewed-by: @isaacs
1 parent 450447f commit 1770f1b

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed
 

‎README.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ Happy hacking!
5656

5757
### API
5858

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

6180
Performs a request to a given URL.
@@ -397,6 +416,9 @@ Force offline mode: no network requests will be done during install. To allow
397416
This option is only really useful if you're also using
398417
[`opts.cache`](#opts-cache).
399418

419+
This option is set to `true` when the request includes `write=true` in the
420+
query string.
421+
400422
##### <a name="opts-otp"></a> `opts.otp`
401423

402424
* Type: Number | String
@@ -408,7 +430,7 @@ account.
408430

409431
##### <a name="opts-password"></a> `opts.password`
410432

411-
* Alias: _password
433+
* Alias: `_password`
412434
* Type: String
413435
* Default: null
414436

@@ -438,6 +460,9 @@ will be requested from the server. To force full offline mode, use
438460
This option is generally only useful if you're also using
439461
[`opts.cache`](#opts-cache).
440462

463+
This option is set to `false` when the request includes `write=true` in the
464+
query string.
465+
441466
##### <a name="opts-prefer-online"></a> `opts.prefer-online`
442467

443468
* Type: Boolean
@@ -449,6 +474,8 @@ for updates immediately even for fresh package data.
449474
This option is generally only useful if you're also using
450475
[`opts.cache`](#opts-cache).
451476

477+
This option is set to `true` when the request includes `write=true` in the
478+
query string.
452479

453480
##### <a name="opts-project-scope"></a> `opts.project-scope`
454481

@@ -612,4 +639,4 @@ See also [`opts.password`](#opts-password)
612639
* Default: null
613640

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

0 commit comments

Comments
 (0)
Please sign in to comment.