Skip to content

Commit

Permalink
Handle attempt to use non-initted cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Jan 16, 2020
1 parent 18243df commit d824c6c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/gatsby/src/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ export default class Cache {

get<T = unknown>(key): Promise<T | undefined> {
return new Promise(resolve => {
// eslint-disable-next-line no-unused-expressions
this.cache?.get<T>(key, (err, res) => {
if (!this.cache) {
resolve(undefined)
return
}
this.cache.get<T>(key, (err, res) => {
resolve(err ? undefined : res)
})
})
Expand All @@ -66,8 +69,11 @@ export default class Cache {
args: CachingConfig = { ttl: TTL }
): Promise<T | undefined> {
return new Promise(resolve => {
// eslint-disable-next-line no-unused-expressions
this.cache?.set(key, value, args, err => {
if (!this.cache) {
resolve(undefined)
return
}
this.cache.set(key, value, args, err => {
resolve(err ? undefined : value)
})
})
Expand Down

0 comments on commit d824c6c

Please sign in to comment.