-
-
Notifications
You must be signed in to change notification settings - Fork 64
Allow maxAgeSinceAccess in addition to maxAge #126
Copy link
Copy link
Open
Labels
Description
This would function similarly to maxAge but the cache would expire x milliseconds from last access as opposed to x milliseconds from the first access.
For example:
memoized = memoize(fn, { maxAgeSinceAccess: 1000 }); // 1 second
memoized("foo", 3);
memoized("foo", 3); // Cache hit
setTimeout(function() {
memoized("foo", 3); // Cache hit
}, 500);
setTimeout(function() {
memoized("foo", 3); // Cache hit since it was accessed at 500ms, thus resetting the "timer".
}, 1000);
setTimeout(function() {
memoized("foo", 3); // No longer in cache, re-executed
memoized("foo", 3); // Cache hit
}, 2000);This makes much more sense to me than maxAge, since we likely don't want to expire a memoized value that is actively being used. preFetch also doesn't make much sense as we likely have no need to recompute the value. We simply want to remove inactive items from the cache.
Reactions are currently unavailable