const cache = new Map();
const inflight = new Map();

export default async function fetchWithCache(key, fetcher){
  if(cache.has(key)) return cache.get(key);
  const p = fetcher().then(res => { cache.set(key, res); inflight.delete(key); return res; });
  inflight.set(key, p);
  return p;
}
Run tests to see results.