Memoized Decorator
A fork of memoized-decorator that takes class properties into consideration by attaching the memoization cache at the object level rather than class level.
Serializes arguments by .toString()
or JSON.strinigify
for objects literals
& arrays. null
& undefined
safe.
Installation
npm install --save memoized-class-decorator
Usage
; ; f1.myMethod5; //= 10 (method is invoked)f1.myMethod10; //= 15 (method is invoked)f1.myMethod5; //= 10 (method is not invoked) ; f2.myMethod5; //= 5 (method is invoked, each object has it's own cache)
Note that if an object is passed to the method with an id
property, the value of that propery will be used as the cache key. This is to reduce the time needed to serialize complex objects.