Memoize/cache function results
npm install memoizee-proxy

Read this in other languages: 简体中文
Memoize based on Proxy.
- [x] Works with any type, any length of function arguments - optional serialization.
- [x] Support for promises and asynchronous functions.
- [x] Configurable weak provides a WeakMap (friendly garbage collection).
- [x] Cache can be managed manually.
- [x] Cache size can be limited on LRU basis.
- [x] Optional reference counter mode, that allows more sophisticated cache management.
- [x] unit tests.
| Property | Description | Type | Default |
| :----| :---- | :---- | :---- |
| normalizer | Generates a unique value based on the current parameter | (args: any[]) => string | Array.from(argument).join(',') |
| weak | Using WeakMap | boolean | false |
| maxAge | Timeout duration, expired delete | number | undefined |
| max | Maximum number of items stored | number | undefined |
| manual | Enable manage the cache manually | boolean | false |
| refCounter | Enable reference counting | boolean | false |
| dispose | Called right before an item is evicted from the cache | (value: T) => void | undefined |
| closeable | Provide use cache toggle function | boolean | false |
``bash`
npm install memoizee-proxy
or
`bash`
yarn add memoizee-proxy
`ts
import {memoizee} from 'memoizee-proxy'
var fn = function(one, two, three) {
/ ... /
};
var memoized = memoizee(fn);
memoized("foo", 3, "bar");
memoized("foo", 3, "bar"); // Cache hit
`
`ts
var afn = function(a, b) {
return new Promise(function(res) {
res(a + b);
});
};
memoized = memoize(afn, { promise: true });
memoized(3, 7);
memoized(3, 7); // Cache hit
``