We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Cache Reaping

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.

Assignment

Run and submit the CLI tests from the root of the repo.

Tip

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.