You have been asked to implement a new feature (with JavaScript) for an application that involves fetching some particular kind of data (on demand) from a third-party service — say GitHub profiles of some popular open source contributors. In no time, you were able to come up with a pretty straightforward implementation — a function named fetchGithubProfile
with a signature like so: (username: string) => Promise<GithubProfile>
.
Later on, you realized that it will be better if the application does not trigger new HTTP requests for profiles that have been fetched before, and so you decided to implement some form of caching — to keep things a bit simple, let's say you decided to use a JavaScript Map with a type like so: Map<string, GithubProfile>
.