MCPcopy Create free account
hub / github.com/astercloud/aster / memoize

Function memoize

ui/src/utils/performance.ts:140–154  ·  view source on GitHub ↗
(func: T, resolver?: (...args: Parameters<T>) => string)

Source from the content-addressed store, hash-verified

138 * 内存化 - 缓存函数结果
139 */
140export 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

Calls 3

hasMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected