Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timeout in memoize after which cache will cleared #462

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
timeout in memoize after which cache will cleared
Jhon-Mosk committed Nov 13, 2023
commit 5965d53f77a65d62e40f0bd694dd1c20d8f56aff
11 changes: 10 additions & 1 deletion lib/memoize.js
Original file line number Diff line number Diff line change
@@ -39,7 +39,16 @@ const memoize = (fn) => {
};

Object.setPrototypeOf(memoized, Memoized.prototype);
return Object.assign(memoized, fields);
const obj = Object.assign(memoized, fields);
Object.defineProperty(obj, 'timeout', {
set(value) {
const timer = setTimeout(() => {
this.cache.clear();
clearTimeout(timer);
}, value);
},
});
return obj;
};

Memoized.prototype.clear = function () {
3,834 changes: 2,754 additions & 1,080 deletions package-lock.json

Large diffs are not rendered by default.