nextRequest
nextRequest ⇒ number
The next number in the order requests start in, unique within the process.
Kind: global constant
byteSize ⇒ number
The size of a string in UTF-8 bytes.
Counted from its UTF-16 code units rather than with Buffer, which webpack would otherwise polyfill into the browser bundle this file is part of.
Kind: global constant
Returns: number - Bytes.
| Param | Type | Description |
|---|---|---|
| text | string | The text to measure. |
configHasCredentials ⇒ boolean
Whether a request config, as sent, carries credentials.
Kind: global constant
| Param | Type | Description |
|---|---|---|
| config | object | The Axios request config. |
| [sessionCookie] | string | A pattern for the session cookie name. |
hasCredentials ⇒ boolean
Whether an Axios instance sends credentials with its requests.
True when its defaults hold credentials, or when a watched request was seen leaving with credentials that an interceptor added.
Kind: global constant
| Param | Type | Description |
|---|---|---|
| axios | object | The Axios instance. |
| [sessionCookie] | string | A pattern for the session cookie name. |
watchCredentials
Watch an Axios instance for credentials added while a request is sent.
A request interceptor can add an Authorization header that the defaults never show. The response holds the config as sent, so the instance is marked there and the cache is withheld from it from then on.
Clients sharing an instance may each configure a different session cookie. One interceptor is registered, against every pattern registered on the instance, so a cookie only the second client would recognise is still seen.
Kind: global constant
| Param | Type | Description |
|---|---|---|
| axios | object | The Axios instance. |
| [sessionCookie] | string | A pattern for the session cookie name. |
parseCacheLifetime ⇒ number
How long a shared cache may keep a response, from its headers.
Follows Cache-Control as a shared cache must: private, no-store or
no-cache forbid storing, s-maxage wins over max-age, time already spent
in a cache in front of Drupal (Age) is taken off, and no directive means 0.
A Vary on any request header other than Cookie or Accept-Encoding also
forbids storing, as the cache key holds nothing that could tell variants apart.
Kind: global constant
Returns: number - Seconds the response may be kept, 0 when it may not.
| Param | Type | Description |
|---|---|---|
| [headers] | object | The response headers. |
processCache ⇒ Object
Get the process cache for a scope.
Returns null in a browser or when the Axios instance sends credentials. An
entry with no lifetime, such as a response Drupal marks no-cache, is never
stored. Each entry lives for the lifetime it is stored with, which comes from
the response's Cache-Control.
Store a value only after its request has resolved, and ask for the cache
again at that point: the request may have shown the instance to be credentialed.
Kind: global constant
| Param | Type | Description |
|---|---|---|
| scope | string | The cache scope, e.g. 'index'. |
| options | object | The cache options. |
| options.axios | object | The Axios instance the request uses. |
| [options.ttl] | number | Seconds an entry may live at most. It shortens a lifetime, never extends one, and 0 keeps nothing. |
| [options.sessionCookie] | string | A pattern for the session cookie name. |
| [options.maxSize] | number | The size the scope keeps per consumer at most, in bytes of stored JSON. Past it, expired entries go first, then the least recently used, and a value larger than the whole limit is not stored. |
| [options.sizeOf] | function | Measures a value for maxSize. The bytes of its JSON by default. |
resetProcessCache
Empty the process cache.
Kind: global constant
| Param | Type | Description |
|---|---|---|
| [scope] | string | The scope to empty. All scopes when omitted. |
set(key, value, seconds, [since]) ⇒ *
Store a value, unless a clear has happened since this handle was taken.
A value that may not be kept also removes what an earlier response stored under the key, so the cache follows Drupal's latest answer.
Kind: global function
Returns: * - The value, stored or not.
| Param | Type | Description |
|---|---|---|
| key | string | The cache key. |
| value | * | The value to store. |
| seconds | number | Seconds the value may be kept. |
| [since] | number | A generation the value was fetched at. The value is dropped when a clear has happened since. |