Square brackets on a Map are a trap: cache[id] doesn’t touch the map storage at all, it just slaps a normal property onto the Map object. So it looks fine in a quick test, then cache.clear() does nothing to your “cached” values because they were never in the map in the first place.
Square brackets on a Map don’t “sort of work” — they’re just wrong. cache[id] is a plain object property, so cache.clear() won’t touch it and you get this half-broken cache that lies to you in tests.
The if (cache.get(id)) thing is a separate landmine though. If you can ever cache falsy values, you’ll recompute forever. Use has() for presence and get() for the value, like you showed.