Skip to content

Commit ed8562b

Browse files
add docs for cacher
1 parent ac02c72 commit ed8562b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/lightning/src/structures/cacher.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
/** a class that wraps map to cache keys */
12
export class cacher<k, v> {
3+
/** the map used to internally store keys */
24
private map = new Map<k, { value: v; expiry: number }>();
35

6+
/** create a cacher with a ttl (defaults to 30000) */
47
constructor(private ttl: number = 30000) {}
58

9+
/** get a key from the map, returning undefined if expired or not found */
610
get(key: k): v | undefined {
711
const time = Temporal.Now.instant().epochMilliseconds;
812
const entry = this.map.get(key);
@@ -12,6 +16,7 @@ export class cacher<k, v> {
1216
return undefined;
1317
}
1418

19+
/** set a key in the map along with its expiry */
1520
set(key: k, val: v, customTtl?: number): v {
1621
const time = Temporal.Now.instant().epochMilliseconds;
1722
this.map.set(key, {

0 commit comments

Comments
 (0)