File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,17 @@ class ExpirableValue implements ExpirableValueInterface {
4
4
public ttl : number ;
5
5
public value : string | Uint8Array | Record < string , unknown > ;
6
6
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
+ */
7
12
public constructor ( value : string | Uint8Array | Record < string , unknown > , maxAge : number ) {
8
13
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 ;
11
18
}
12
19
13
20
public isExpired ( ) : boolean {
You can’t perform that action at this time.
0 commit comments