Also that cache “pattern” has a race condition if its called twice in quick succession (it may end up calling the server twice) as there is a window of opportunity during the “await” for the server call.
The pattern I tend use roughly (untested code) like this:
const cache = { /* url: content */ }; // Async function that returns cached content or retrieves fresh content async function getInfo(url) { // Check for value in cache if (!cache[url]) { cache[url] = fetch("https://www.facebook.com").then(r => r.text()); } return cache[url]; }
There isn’t any real need for an “await” inside the function…