Skip to content

Commit ab13a0d

Browse files
authored
fix: primeLoader should respect cachePrefix, and always update if cached (#52)
1 parent 59dad7d commit ab13a0d

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/cache.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ export const createCachingMethods = <DType extends { id: string }>({
108108
* Use this when running a query outside of the findOneById/findManyByIds methos
109109
* that automatically and transparently do this
110110
*/
111-
primeLoader: (docs, ttl?: number) => {
111+
primeLoader: async (docs, ttl?: number) => {
112112
docs = Array.isArray(docs) ? docs : [docs];
113-
docs.forEach((doc) => {
114-
const key = doc.id;
115-
loader.prime(key, doc);
116-
if (ttl) {
113+
for (const doc of docs) {
114+
loader.prime(doc.id, doc);
115+
const key = cachePrefix + doc.id;
116+
if (ttl || await cache.get(key)) {
117117
cache.set(key, EJSON.stringify(doc), { ttl });
118118
}
119-
});
119+
}
120120
},
121121
dataLoader: loader,
122122
};

0 commit comments

Comments
 (0)