Back to problems

Review an Asynchronous Cache for Races, Memory Growth, and Thread Safety

Algorithm · Mercor · Hard

Consider this initial implementation of an asynchronous cache for a JavaScript service: The intended behavior is to cache the result of asyncFetch(key) and return the same value to all callers for the same key. The code is not correct as written. Part 1 — Correctness and Asynchronous Interleaving Identify all syntax/API defects in the draft. Then explain the interleaving that occurs when two read calls for the same missing key are both in flight before either asyncFetch(key)…

Checking your access…