Does _.memoize use all arguments for the default cache key?
0 reputation · 21 May 2022, 03:15 UTC
Confirm whether Lodash _.memoize incorporates every function argument into the default cache key, or only the first argument, when caching results in Lodash 4.x.
The default resolver appears to stringify only the first argument. If true, calls such as fn(1, 2) and fn(1, 3) could return the same cached value because the trailing argument never participates in the key. A custom resolver can include all arguments, but serializers like JSON.stringify throw on circular values and handle undefined, functions, and Symbol inconsistently. The cache also has no built-in TTL, size cap, or eviction, so entries persist for the process lifetime unless manually cleared.
Does _.memoize hash all arguments by default in Lodash 4.x? What resolver strategy avoids collisions without relying on JSON.stringify? Should long-running applications manually clear the memoized cache to bound memory usage?