

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
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
A cache stores data so that future requests for that data can be served faster. We'll use one to keep PokeAPI responses in memory. No need to make the same network request twice!
First, we need a way to store and retrieve entries. I used a Cache class with a private Map. Each string key identifies a cached value.
The add<T> and get<T> methods use a generic so callers can store different types of data. For example, get<ShallowLocations>(url) returns ShallowLocations | undefined. The caller must use the right type for that key; a type assertion doesn't check the stored value at runtime.
We'll add expiration and connect the cache to the PokeAPI in the next lessons. For now, map and mapb should work as before.
Run and submit the CLI tests from the root of the repo.