Skip to content

Commit dc082bf

Browse files
committed
Add support for passing a callback to prime cache
1 parent 01243d5 commit dc082bf

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

.changeset/tiny-pianos-leave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@labdigital/dataloader-cache-wrapper': minor
3+
---
4+
5+
Add support for adding a callback to prime the dataloader cache

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type cacheOptions<K, V> = {
99
bachLoadFn: DataLoader.BatchLoadFn<K, V>
1010
cacheKeysFn: (ref: K) => string[]
1111
lookupFn: (items: V[], ref: K) => V | undefined
12+
primeFn?: (items: V[]) => void
1213
}
1314

1415
// dataloaderCache is a wrapper around the dataloader batchLoadFn that adds
@@ -89,6 +90,7 @@ const fromCache = async <K, V>(
8990
.map((v: string) => JSON.parse(v))
9091
}
9192

93+
// Write items to the cache
9294
const toCache = async <K, V>(
9395
items: Map<string, V>,
9496
options: cacheOptions<K, V>

0 commit comments

Comments
 (0)