Skip to content

Commit 3fea0d7

Browse files
committed
Use timestamp/millisecond based math for checking expiration.
1 parent 2d80baa commit 3fea0d7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Diff for: packages/parameters/src/ExpirableValue.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ class ExpirableValue implements ExpirableValueInterface {
44
public ttl: number;
55
public value: string | Uint8Array | Record<string, unknown>;
66

7+
/**
8+
* Creates a new cached value which will expire automatically
9+
* @param value Parameter value to be cached
10+
* @param maxAge Maximum number of seconds to cache the value for
11+
*/
712
public constructor(value: string | Uint8Array | Record<string, unknown>, maxAge: number) {
813
this.value = value;
9-
const timeNow = new Date();
10-
this.ttl = timeNow.setSeconds(timeNow.getSeconds() + maxAge);
14+
15+
const maxAgeInMilliseconds = maxAge * 1000;
16+
const nowTimestamp = Date.now();
17+
this.ttl = nowTimestamp + maxAgeInMilliseconds;
1118
}
1219

1320
public isExpired(): boolean {

0 commit comments

Comments
 (0)