Skip to content

Commit

Permalink
fix: Set cache overflow of the setTimeout Maximum delay value (#1742)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenli1989 authored Mar 25, 2022
1 parent d31cb90 commit 0c633ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils/cache/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ export class Memory<T = any, V = any> {
return value;
}
const now = new Date().getTime();
item.time = now + expires;
/**
* Prevent overflow of the setTimeout Maximum delay value
* Maximum delay value 2,147,483,647 ms
* https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value
*/
item.time = expires > now ? expires : now + expires;
item.timeoutId = setTimeout(
() => {
this.remove(key);
Expand Down

0 comments on commit 0c633ff

Please sign in to comment.