| 29 | } |
| 30 | |
| 31 | async function initEntries( |
| 32 | cacheDir: string |
| 33 | ): Promise<Array<{ key: string; size: number; expireAt: number }>> { |
| 34 | const keys = await promises.readdir(cacheDir).catch(() => []) |
| 35 | const entries: Array<{ key: string; size: number; expireAt: number }> = [] |
| 36 | |
| 37 | for (const key of keys) { |
| 38 | const { size, expireAt } = await readEntry(cacheDir, key) |
| 39 | entries.push({ key, size, expireAt }) |
| 40 | } |
| 41 | |
| 42 | // Sort oldest-first so we can replay them chronologically into LRU |
| 43 | return entries.sort((a, b) => a.expireAt - b.expireAt) |
| 44 | } |
| 45 | |
| 46 | async function rmEntry(cacheDir: string, cacheKey: string): Promise<void> { |
| 47 | await promises.rm(join(cacheDir, cacheKey), { |