Skip to content

The core module, DruxtClient, DruxtStore and the DruxtModule base component.

nextRequest

View source on GitHub

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.

ParamTypeDescription
textstringThe text to measure.

configHasCredentials ⇒ boolean

Whether a request config, as sent, carries credentials.

Kind: global constant

ParamTypeDescription
configobjectThe Axios request config.
[sessionCookie]stringA 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

ParamTypeDescription
axiosobjectThe Axios instance.
[sessionCookie]stringA 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

ParamTypeDescription
axiosobjectThe Axios instance.
[sessionCookie]stringA 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.

ParamTypeDescription
[headers]objectThe 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

ParamTypeDescription
scopestringThe cache scope, e.g. 'index'.
optionsobjectThe cache options.
options.axiosobjectThe Axios instance the request uses.
[options.ttl]numberSeconds an entry may live at most. It shortens a lifetime, never extends one, and 0 keeps nothing.
[options.sessionCookie]stringA pattern for the session cookie name.
[options.maxSize]numberThe 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]functionMeasures a value for maxSize. The bytes of its JSON by default.

resetProcessCache

Empty the process cache.

Kind: global constant

ParamTypeDescription
[scope]stringThe 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.

ParamTypeDescription
keystringThe cache key.
value*The value to store.
secondsnumberSeconds the value may be kept.
[since]numberA generation the value was fetched at. The value is dropped when a clear has happened since.