Adding syntactic sugar to npm package memoizee, cache function using the elegant TypeScript decorator.
$ npm install memoizee-decorator --save
Cache a function
import {memoize} from 'memoizee-decorator';
@memoize()
function add(a, b) {
console.log('add is called');
return a + b;
}
add(1, 2); // log "add is called"
add(1, 2); // cache hit, no log
add(3, 4); // log "add is called"
same configuration object as the one in memoizee package
import {memoize} from 'memoizee-decorator';
@memoize({max: 5}) // put configuration object here
function add(a, b) {
return a + b;
}