The name given to this DataLoader
instance. Useful for APM tools.
Is null
if not set in the constructor.
Clears the value at key
from the cache, if it exists. Returns itself for
method chaining.
Clears the entire cache. To be used when some event results in unknown
invalidations across this particular DataLoader
. Returns itself for
method chaining.
Loads multiple keys, promising an array of values:
var [ a, b ] = await myLoader.loadMany([ 'a', 'b' ]);
This is similar to the more verbose:
var [ a, b ] = await Promise.all([
myLoader.load('a'),
myLoader.load('b')
]);
However it is different in the case where any load fails. Where Promise.all() would reject, loadMany() always resolves, however each result is either a value or an Error instance.
var [ a, b, c ] = await myLoader.loadMany([ 'a', 'b', 'badkey' ]);
// c instanceof Error
A
DataLoader
creates a public API for loading data from a particular data back-end with unique keys such as theid
column of a SQL table or document name in a MongoDB database, given a batch loading function.Each
DataLoader
instance contains a unique memoized cache. Use caution when used in long-lived applications or those which serve many users with different access permissions and consider creating a new instance per web request.