https://github.com/blackchef/shallowmemoize
Shallow compare function arguments for memoization.
https://github.com/blackchef/shallowmemoize
Last synced: 11 months ago
JSON representation
Shallow compare function arguments for memoization.
- Host: GitHub
- URL: https://github.com/blackchef/shallowmemoize
- Owner: blackChef
- Created: 2017-06-15T08:43:46.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-02-28T09:44:02.000Z (over 2 years ago)
- Last Synced: 2024-12-07T03:39:07.745Z (over 1 year ago)
- Language: JavaScript
- Size: 41 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ShallowMemoize
Memoization with ability to set cache size and use shallow comparison.
# Usage
```js
import memoize from 'shallow-memoize'
let memoizeOptions = {
cacheSize: 1, // size of cache, should be greater than 0. Default is Infinity.
useShallowCompare: true, // whether shallow compare should be used. Default is false.
};
let add = memoize(function(a, b) {
return a.val + b.val;
}, memoizeOptions);
add({ val: 5 }, { val: 5 });
add({ val: 5 }, { val: 5 }); // cache hit
add({ val: 3 }, { val: 3 });
add({ val: 3 }, { val: 3 }); // cache hit
add({ val: 5 }, { val: 5 }); // no cache, because cache size is 1
```