Memoizes a function. If the params passed to the function are the same
as a previous call, then the cached results are returned, saving an
unncessary excecution.
Consider the follwing example
letexpensiveCalculation = func.memoize((a,b,c)=> { returna + b + c; })
expensiveCalculation(1, 1, 1); // 3, callback executed and results cached. expensiveCalculation(1, 1, 1); // 3 from cache expensiveCalculation(1, 1, 1); // 3 from cache
expensiveCalculation(2, 2, 2); // 6, callback executed and results cached. expensiveCalculation(2, 2, 2); // 6 from cache
expensiveCalculation(1, 1, 1); // 3 from cache expensiveCalculation(2, 2, 2); // 6 from cache
A common case for memoize might be to use it in a class method.
You can implement that with this pattern.
Memoizes a function. If the params passed to the function are the same as a previous call, then the cached results are returned, saving an unncessary excecution.
Consider the follwing example
A common case for memoize might be to use it in a class method. You can implement that with this pattern.