Promise.all(), Promise.race(), and Promise.any()
What optimization pattern is demonstrated here?
const cache = new Map();
async function fetchWithCache(urls) {
const promises = urls.map(url => {
if (cache.has(url)) return cache.get(url);
const promise = fetch(url).then(r => r.json());
cache.set(url, promise);
return promise;
});
return Promise.all(promises);
}