Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 818 Bytes

README.md

File metadata and controls

39 lines (28 loc) · 818 Bytes

memoizee-decorator

Adding syntactic sugar to npm package memoizee, cache function using the elegant TypeScript decorator.

Installing

$ npm install memoizee-decorator --save

Example

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"

Fit memoizee configuration into the decorator.

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;
}