Function
memoize
(func: T, resolver?: (...args: Parameters<T>) => string)
Source from the content-addressed store, hash-verified
| 138 | * 内存化 - 缓存函数结果 |
| 139 | */ |
| 140 | export function memoize<T extends (...args: any[]) => any>(func: T, resolver?: (...args: Parameters<T>) => string): T { |
| 141 | const cache = new Map<string, ReturnType<T>>(); |
| 142 | |
| 143 | return function (this: any, ...args: Parameters<T>): ReturnType<T> { |
| 144 | const key = resolver ? resolver(...args) : JSON.stringify(args); |
| 145 | |
| 146 | if (cache.has(key)) { |
| 147 | return cache.get(key)!; |
| 148 | } |
| 149 | |
| 150 | const result = func.apply(this, args); |
| 151 | cache.set(key, result); |
| 152 | return result; |
| 153 | } as T; |
| 154 | } |
Callers
nothing calls this directly
Tested by
no test coverage detected