Other than remembering commonly used invocations, another big use case for a cache is knowing when an item is time-stale.
Currently doing this with a Map or Set is possible by wrapping it manually, but having it wrapped outside has drawbacks that inclusion here could tackle
The different policy types can first clear an expired entry when size limits are reached, meaning living data may persist longer
Time checking can be implemented closer to the metal
ttl would default to never expires when not provided, and could be provided either at the level of the whole map/set as an option at construction time, or by adding an additional parameter to the .set method
const m = new Foo();
m.set('key', 'value', msToLive);
// or
m.set('key', 'value', { ttl: msToLive });
Other than remembering commonly used invocations, another big use case for a cache is knowing when an item is time-stale.
Currently doing this with a Map or Set is possible by wrapping it manually, but having it wrapped outside has drawbacks that inclusion here could tackle
ttl
would default to never expires when not provided, and could be provided either at the level of the whole map/set as an option at construction time, or by adding an additional parameter to the.set
method