a-synchronous / a-synchronous/rubico
rubico/x/memoize
- 主要语言
- JavaScript
- 星标
- 283
- 派生
- 17
- PR 合并指标
- 30 天内没有已合并 PR
描述
### memoize
```coffeescript
var key any,
cache Mapany>,
funcArgs ...any,
func ...funcArgs=>Promise|any,
maxCacheSize number,
cacheClearer (cache, ...funcArgs)=>Promise<>|key
memoize(func) -> memoized function
memoized.cache -> cache
memoize(func, options {
cacheSize: number,
}) -> memoizedCapped function
memoizedCapped.cache -> cache
```
Memoize (create a cached version of) a function using its first argument as the cache key. If `cacheSize` is provided, it is used to indicate the maximum size of the internal cache. If the number of items in the cache exceeds this number, the cache is cleared. If instead `cacheClearer` is provided, it is called with a reference to the internal cache and any arguments supplied to the memoized function.
Note: Any effects of `func` will not be rerun on cache hit.
```javascript
const identity = value => value
const square = number => number ** 2
const memoizedCapped500Square = memoize(square, { cacheSize: 500 })
console.log(memoizedCapped500Square(3)) // 9
console.log(memoizedCapped500Square.cache) // Map { 3 => 9 }
```
贡献指南
评估
这个 Issue 还没有评估数据。