a-synchronous / a-synchronous/rubico

rubico/x/memoize

未關閉
#105 0 則留言 0 個 reaction 已指派 1 人 已被 @richytong 認領 在 GitHub 檢視
enhancement
主要語言
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 }
```

貢獻指南

開啟貢獻指南

研究方向

Look at the existing memoize implementation in the codebase to understand the current caching behavior. The task is to add cache size limiting and a custom cache clearer. Start by examining how the cache Map is managed and where eviction logic would fit. Write tests for the new options to verify cache size enforcement and clearer invocation.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
javascript
領域
tooling
Issue 類型
功能
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。