-
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,23 +37,21 @@ | |
"devDependencies": { | ||
"@changesets/cli": "^2.26.1", | ||
"@labdigital/eslint-config-node": "^0.0.5", | ||
"@types/ioredis-mock": "^8.2.5", | ||
"@types/object-hash": "^3.0.6", | ||
"@vitest/coverage-v8": "^0.33.0", | ||
"dataloader": "^2.2.2", | ||
"eslint-plugin-unused-imports": "^2.0.0", | ||
"eslint": "^8.40.0", | ||
"ioredis-mock": "^8.9.0", | ||
"ioredis": "^5.3.2", | ||
"eslint-plugin-unused-imports": "^2.0.0", | ||
"tsup": "6.7.0", | ||
"typescript": "5.0.4", | ||
"vitest": "^0.33.0" | ||
}, | ||
"peerDependencies": { | ||
"dataloader": "^2.2.2", | ||
"ioredis": "^5.3.2" | ||
"keyv": "^4.5.4" | ||
}, | ||
"dependencies": { | ||
"object-hash": "^3.0.0" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha512.c85cd21b6da10332156b1ca2aa79c0a61ee7ad2eb0453b88ab299289e9e8ca93e6091232b25c07cbf61f6df77128d9c849e5c9ac6e44854dbd211c49f3a67adc" | ||
} |
Oops, something went wrong.