Skip to content

Commit

Permalink
Fix getAll method of file cache
Browse files Browse the repository at this point in the history
  • Loading branch information
bahung1221 committed Oct 28, 2019
1 parent a961483 commit 1b2e14b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/core/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ module.exports = class FileStore {
let val = null,
cacheFile = path.join(this.path, key + '.json')

if (!this.cache[key]) {
return fn(null, null)
}

Fs.exists(cacheFile, (isExists) => {
if (isExists) {
Fs.readFile(cacheFile, (err, data) => {
if (err) return fn(err)

data = JSON.parse(data)

if (!this.cache[key]) {
return fn(null, null)
}

if (!data) return fn(null, data)
if (data.expire < Date.now()) {
this.remove(key)
Expand All @@ -94,6 +94,7 @@ module.exports = class FileStore {
})
})
} else {
delete this.cache[key]
return fn(null, null)
}
})
Expand Down Expand Up @@ -196,7 +197,7 @@ module.exports = class FileStore {

entries.push({ key: entry, value: data })

if (index === keys.length - 1) fn(null, entries)
if (entries.length === keys.length) fn(null, entries)
})
})
}
Expand Down

0 comments on commit 1b2e14b

Please sign in to comment.