Wrap a unary function with a per-argument cache. Results are keyed by reference/value equality via Map, so non-primitive keys must be the same reference to hit the cache.
Map
const fetchUser = memoize(async (id: string) => db.users.findById(id)) await fetchUser("u_1") // miss await fetchUser("u_1") // hit Copy
const fetchUser = memoize(async (id: string) => db.users.findById(id)) await fetchUser("u_1") // miss await fetchUser("u_1") // hit
Wrap a unary function with a per-argument cache. Results are keyed by reference/value equality via
Map, so non-primitive keys must be the same reference to hit the cache.