Skip to content

Commit

Permalink
fix: fixed cache, querying the server even if valid cache is present
Browse files Browse the repository at this point in the history
  • Loading branch information
liquiddevelopmentnet committed Dec 26, 2023
1 parent 73b1330 commit 3975b16
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ export class Service {
const currentMethod = this[name as keyof Service]

this[name as keyof Service] = async (...args: never[]) => {
const result = await currentMethod.apply(this, args)
const key = JSON.stringify({ k: name, a: args })

const cached = this._cache.get(key)
if (cached && Date.now() - cached.t < cacheFor) {
return cached.d
} else {
const result = await currentMethod.apply(this, args)
this._cache.set(key, { d: result, t: Date.now() })
return result
}
Expand Down

0 comments on commit 3975b16

Please sign in to comment.