Skip to content

Commit

Permalink
fix: early return cache data if value object empty
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrani committed May 15, 2024
1 parent 78cd6d4 commit 58add6c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/stores/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export default class CacheStore {
return this.#cache
}

isEmpty(obj) {
return Object.keys(obj).length === 0 && obj.constructor === Object;
}

getKey(key) {
const result = this.#cache.getItem(key)
try { return JSON.parse(result) }
Expand All @@ -14,7 +18,7 @@ export default class CacheStore {

getValue({ key, value }) {
const result = this.getKey(key)
if (result) return result
if (result && this.isEmpty(value)) return result

return this.update({ key, value })
}
Expand Down

0 comments on commit 58add6c

Please sign in to comment.