Several proposed performance changes need the same asynchronous caching
pattern: return an existing promise for a key, or create and cache one on a
miss. Caching the promise deduplicates concurrent calls as well as later calls.
A shared utility would avoid repeating this logic and provide consistent
choices for:
Map or WeakMap storage, depending on key lifetime;
- eviction after rejection, so transient failures can be retried;
- per-instance method caching through a decorator; and
- custom key derivation for methods with multiple arguments.
The utility itself does not alter an existing hot path. Its performance effect
should be measured in the changes that adopt it.
Several proposed performance changes need the same asynchronous caching
pattern: return an existing promise for a key, or create and cache one on a
miss. Caching the promise deduplicates concurrent calls as well as later calls.
A shared utility would avoid repeating this logic and provide consistent
choices for:
MaporWeakMapstorage, depending on key lifetime;The utility itself does not alter an existing hot path. Its performance effect
should be measured in the changes that adopt it.