Decorator to memoize a class method.
Mem is used as caching library. When using with Typescript, don't forget to enable the flag "experimentalDecorators": true
in tsconfig.json
.
Requirements
- Node >= 8
Install
$ npm install mem-decorator --save
Usage
const memoize = ; @ { // Fibonacci algorithm } const fib = console // Calculation executed (1)console // Calculation executed (2)console // Cache hit, returning previous calculation (1)
API
@memoize([configuration])
Annotation to memoize a class method. Works for getters as well.
configuration
Required: false
Type: object
Uses the same configuration as mem
License
MIT © Simon Jang