deep-data-loader
v0.0.2
Published
A utility for batching and caching requests.
Downloads
1
Readme
deep-data-loader
DeepDataLoader is a utility class that allows the batching and caching of requests across two levels.
Get Started
Install DeepDataLoader using npm.
npm install --save deep-data-loader
Create a DeepDataLoader
instance, passing in an array of primary keys and optionally an array of secondary keys.
const DeepDataLoader = require('deep-data-loader);
const userLoader = new DeepDataLoader((primaryKeys, secondaryKeys) => batchLoadFn(primaryKeys, secondaryKeys));
Each instance of the DeepDataLoader
class represents a unique cache. This cache can be initialised once per app or once per request.
⚠️ If the cache is initialised per application, it may lead to an unintended memory leak.
The keys accepted by the batchLoadFn
should be in the form of arrays of any type. Using arrays of structural types (non-primitive types) such as objects or arrays is possible but matching is done by reference (remember {a: 1} !== {a: 1}
).