@labdigital/dataloader-cache-wrapper
v0.5.0
Published
Wrapper around dataloader to cache the results of the loader
Downloads
2,239
Keywords
Readme
node-dataloader-cache-wrapper
Usage
import { dataloaderCache } from "@labdigital/dataloader-cache-wrapper"
export const createProductBySlugLoader = () => {
return new DataLoader<ProductReference, any>(ProductDataLoader, {
maxBatchSize: 50,
});
};
export const ProductDataLoader = async (keys: readonly any[]): Promise<(Product | null)[]> => {
return dataloaderCache(_uncachedProductDataLoader, keys, {
store: new Keyv(),
ttl: 3600,
cacheKeysFn: (ref: ProductRef) => {
const key = `${ref.store}-${ref.locale}-${ref.currency}`;
return [`some-data:${key}:id:${ref.slug}`];
},
})
}