Skip to content

Commit 94cf500

Browse files
authored
Merge pull request #26 from GraphQLGuide/adi-cache-clear
deleteFromCacheById improvements
2 parents c94e466 + 0850ddb commit 94cf500

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ declare module 'apollo-datasource-mongodb' {
4040
options?: Options
4141
): Promise<(TData | null | undefined)[]>
4242

43-
deleteFromCacheById(id: ObjectId): void
43+
deleteFromCacheById(id: ObjectId): Promise<void>
4444
}
4545
}

src/cache.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ export const createCachingMethods = ({ collection, cache }) => {
4141
findManyByIds: (ids, { ttl } = {}) => {
4242
return Promise.all(ids.map(id => methods.findOneById(id, { ttl })))
4343
},
44-
deleteFromCacheById: id => cache.delete(cachePrefix + id)
44+
deleteFromCacheById: async id => {
45+
loader.clear(id)
46+
await cache.delete(cachePrefix + id)
47+
}
4548
}
4649

4750
return methods

0 commit comments

Comments
 (0)