https://github.com/cyan33/memoize
A JavaScript function wrapper to memorize / cache result with the same input
https://github.com/cyan33/memoize
cache funcional-programming wrapper
Last synced: 8 months ago
JSON representation
A JavaScript function wrapper to memorize / cache result with the same input
- Host: GitHub
- URL: https://github.com/cyan33/memoize
- Owner: cyan33
- License: mit
- Created: 2017-10-18T19:00:42.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-28T21:04:47.000Z (over 8 years ago)
- Last Synced: 2025-02-11T02:19:30.100Z (about 1 year ago)
- Topics: cache, funcional-programming, wrapper
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# memoize
:beginner: A JavaScript function wrapper to memorize / cache result with the same input
# Installation
```
npm install --save @changyan/memoize
```
# Basic Usage
```js
import { memoize, memoizeAsync } from '@changyan/memoize'
const add = (a, b) => a + b
const memoizedAdd = memoize(add)
memoizedAdd(1, 2) // => 3
memoizedAdd(1, 2) // => return the cached "3"
const getFakeAsyncResult = () => new Promise((resolve, reject) => setTimeout(resolve, 1000))
// and it supports caching async functions
const memoizedGetAsyncResult = memoizeAsync(getFakeAsyncResult)
```
## Contribution
PRs are welcomed!