Skip to content

use memoizee as TypeScript decorator, cache function result in a simple, elegant way

Notifications You must be signed in to change notification settings

zhaosiyang/memoizee-decorator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

use memoizee as TypeScript decorator, cache function result in a simple, elegant way

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published