I have a slow function
function f(a, b, c) {
}
I call this function with same arguments sometimes, it will return the same result. I want to cache this function call with arguments, so second call with same arguments returns from cache.
I tried this but it doesn't work.
export function memoize(fn) {
let cache;
let res;
return function(...args) {
if (!cache) {
cache = args;
res = fn(...args); return res;
}
if (objectCompare(args, cache)) {
return res; }
return res = fn(...args);
};
}