| 38 | ) {} |
| 39 | |
| 40 | async load(): Promise<void> { |
| 41 | try { |
| 42 | const raw = await readFile(this.cachePath, "utf8"); |
| 43 | const parsed = JSON.parse(raw) as { at: number; tles: Tle[] }; |
| 44 | this.tles = parsed.tles ?? []; |
| 45 | this.fetchedAt = parsed.at ?? 0; |
| 46 | } catch { |
| 47 | /* first run */ |
| 48 | } |
| 49 | // Refresh on startup (non-blocking) and then on a daily timer. |
| 50 | void this.refresh(); |
| 51 | setInterval(() => void this.refresh(), 6 * 3600_000).unref?.(); |
| 52 | } |
| 53 | |
| 54 | async get(): Promise<Tle[]> { |
| 55 | if (Date.now() - this.fetchedAt > this.ttlMs) await this.refresh(); |