Memily
Javascript memoization library. Wrap your computationally expensive functions with memily
so that the results of calls are cached.
Browser Compatibility
This package is dependendent on the ES6 Map feature, which is available in most modern browsers. Consider using a polyfill such as core-js
for legacy browser support.
Installation
Install memily
to your project by running:
npm install --save memily
Or if you use Yarn:
yarn add memily
Then, import memily into your project like this:
import memily from 'memily';
Examples
Basic Usage
import memily from 'memily'; { console; return Math;} const squareRootMemoized = ; ; // console.log: 'Hello world!'; // ...; // ...; // console.log: 'Hello world!'
maxAge
option.
Caching for a finite time using { console; return Math;} const squareRootMemoized = ; Promise // console.log: 'Hello world!' // ... ; // console.log: 'Hello world!'
cacheKey
option.
Caching against a custom key using the const steveHolt = id: 1 firstName: 'Steve' surname: 'Holt'; const tobiasFunke = id: 2 firstName: 'Tobias' surname: 'Funke'; { console; return ` `;} const getFullNameStringMemoized = ; ; // console.log: 'Hello world!'; // ...; // console.log: 'Hello world!'; // ...
Flushing the memoization cache
import flush from 'memily'; ;
Flow Types
Memily comes with Flow types built in. No flow-typed
installation required.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Acknowledgements
Memily was heavily inspired and influenced by sindresorhus's mem package.