0.6.2 • Published 8 months ago

@labdigital/dataloader-cache-wrapper v0.6.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

node-dataloader-cache-wrapper

Usage

import { DataLoaderCache } from "@labdigital/dataloader-cache-wrapper"

const loader = new DataLoaderCache<ProductReference, any>(ProductDataLoader, {
	cache: {
		storeFn: () => new Keyv(),
		ttl: 3600,
	},
	cacheKeyFn: (ref: ProdProductReferenceuctRef) => {
		const key = `${ref.store}-${ref.locale}-${ref.currency}`;
		return `some-data:${key}:id:${ref.slug}`
	},
	maxBatchSize: 50,
});

Or use the older API with the dataloaderCache function:

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: ProductReference) => {
      const key = `${ref.store}-${ref.locale}-${ref.currency}`;
      return [`some-data:${key}:id:${ref.slug}`];
    },
  })
}
0.6.2

8 months ago

0.5.0

1 year ago

0.4.0

1 year ago

0.6.1

8 months ago

0.6.0

8 months ago

0.5.1

8 months ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.3

2 years ago

0.1.1

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.2

3 years ago

0.0.1

3 years ago