

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: State
incomplete
2: PokeAPI
incomplete
3: Cache Add/Get
incomplete
4: Cache Reaping
incomplete
5: Cache Integration
incomplete
6: Explore
incomplete
7: Catch
incomplete
8: Inspect
incomplete
This lesson's interactive features are locked, please to keep using them
Our cache keeps everything forever. Let's clean up old entries so it doesn't keep growing as we explore.
We'll record when each entry was added, then use setInterval to check for old entries. This cleanup is called reaping. Use the same interval for the timer and the maximum entry age. For example, with a 5-second interval, each cleanup removes entries older than 5 seconds. An entry can stay in the cache until the next cleanup after it expires.
A Node.js interval keeps the process running, so we'll also need a way to stop it with clearInterval.
Run and submit the CLI tests from the root of the repo.
Wrap assertions in try/finally and stop the timer in finally. You can use Vitest's expect.poll to wait for an entry to disappear without relying on one perfectly timed check.