2.1.1 • Published 8 months ago
@pacote/memoize v2.1.1
@pacote/memoize
Speed up consecutive calls of the same function with the same arguments by caching its results.
Installation
yarn add @pacote/memoize
Usage
import { memoize } from '@pacote/memoize'
const randomFunction = (prefix: string) => `${prefix}${Math.random()}`
const memoizedFunction = memoize((prefix) => `key_${prefix}`, randomFunction)
memoizedFunction('foo') // 'foo' followed by randomly-generated number.
memoizedFunction('foo') // Same result as previous call with 'foo'.
memoizedFunction('bar') // 'bar' followed by randomly-generated number.
memoizedFunction('bar') // Same result as previous call with 'bar'.
memoize<A, T>(cacheKeyFn: (...args: A) => string, fn: (...args: A) => T): (...args: A) => T
memoize()
takes two function arguments:
A function that generates a string key for cached results. This function takes the same arguments as the function to memoize.
The function to memoize.
memoize()
returns a version of this function that caches results.
License
MIT © Luís Rodrigues.
2.1.1
8 months ago
2.0.2
11 months ago
2.1.0
11 months ago
2.0.1
1 year ago
2.0.0
1 year ago
1.1.8
2 years ago
1.1.6
3 years ago
1.1.5
3 years ago
1.1.4
3 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.1
4 years ago
1.1.0
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago