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 Add/Get

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.

Assignment

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.