File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed
packages/lightning/src/structures Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change
1
+ /** a class that wraps map to cache keys */
1
2
export class cacher < k , v > {
3
+ /** the map used to internally store keys */
2
4
private map = new Map < k , { value : v ; expiry : number } > ( ) ;
3
5
6
+ /** create a cacher with a ttl (defaults to 30000) */
4
7
constructor ( private ttl : number = 30000 ) { }
5
8
9
+ /** get a key from the map, returning undefined if expired or not found */
6
10
get ( key : k ) : v | undefined {
7
11
const time = Temporal . Now . instant ( ) . epochMilliseconds ;
8
12
const entry = this . map . get ( key ) ;
@@ -12,6 +16,7 @@ export class cacher<k, v> {
12
16
return undefined ;
13
17
}
14
18
19
+ /** set a key in the map along with its expiry */
15
20
set ( key : k , val : v , customTtl ?: number ) : v {
16
21
const time = Temporal . Now . instant ( ) . epochMilliseconds ;
17
22
this . map . set ( key , {
You can’t perform that action at this time.
0 commit comments