-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Move to
keyv
as cache implementation.
Move to `keyv` as cache implementation. This makes it compatible with various cache implementations. To update replace the `client` option with `store` and pass a `Keyv` instance.
- Loading branch information
1 parent
96da1c1
commit 3fbea90
Showing
6 changed files
with
3,538 additions
and
2,836 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
'@labdigital/dataloader-cache-wrapper': minor | ||
--- | ||
|
||
Move to `keyv` as cache implementation. This makes it compatible with various | ||
cache implementations. To update replace the `client` option with `store` and | ||
pass a `Keyv` instance. | ||
|
||
```ts | ||
|
||
|
||
import { dataloaderCache } from "@labdigital/dataloader-cache-wrapper" | ||
import Keyv from 'keyv'; | ||
|
||
const redis = new Redis('redis://user:pass@localhost:6379'); | ||
const keyvRedis = new KeyvRedis(redis); | ||
|
||
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({ store: keyvRedis }), | ||
ttl: 3600, | ||
|
||
cacheKeysFn: (ref: ProductRef) => { | ||
const key = `${ref.store}-${ref.locale}-${ref.currency}`; | ||
return [`some-data:${key}:id:${ref.slug}`]; | ||
}, | ||
}) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.