lodash _.memoize cache retains entries indefinitely without eviction
0 reputation · 08 Dec 2023, 17:59 UTC
lodash _.memoize unbounded cache retention
The goal is to use lodash _.memoize in a low-traffic Node service without allowing the memoization cache to grow without bound from unique or high-cardinality arguments.
In lodash 4.x, _.memoize stores results in a .cache Map keyed by the first argument or a custom resolver and retains entries until the process exits or the caller invokes fn.cache.clear(). The API exposes no maximum size, TTL, or automatic eviction policy, so cache growth depends on argument variety and manual intervention. It is unresolved whether indefinite retention is acceptable for this workload or whether a size-limited wrapper is necessary.
- Does lodash 4.x _.memoize include any built-in option to bound cache size or expire stale entries?
- If no built-in limit exists, what is the recommended pattern for manually evicting entries from
.cachewhile preserving correct memoization? - For a low-traffic workload, should unbounded _.memoize retention be treated as acceptable, or is an external size-limited cache preferred?