2.1.2 • Published 9 months ago
@pacote/memoize v2.1.2
@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.2
9 months ago
2.1.1
2 years ago
2.0.2
2 years ago
2.1.0
2 years ago
2.0.1
2 years ago
2.0.0
2 years ago
1.1.8
3 years ago
1.1.6
4 years ago
1.1.5
5 years ago
1.1.4
5 years ago
1.1.3
5 years ago
1.1.2
5 years ago
1.1.1
5 years ago
1.1.0
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
7 years ago
1.0.0
7 years ago