MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / memoizeWithLRU

Function memoizeWithLRU

source code/utils/memoize.ts:236–271  ·  view source on GitHub ↗
(
  f: (...args: Args) => Result,
  cacheFn: (...args: Args) => string,
  maxCacheSize: number = 100,
)

Source from the content-addressed store, hash-verified

234 * @returns A memoized version of the function with cache management methods
235 */
236export function memoizeWithLRU<
237 Args extends unknown[],
238 Result extends NonNullable<unknown>,
239>(
240 f: (...args: Args) => Result,
241 cacheFn: (...args: Args) => string,
242 maxCacheSize: number = 100,
243): LRUMemoizedFunction<Args, Result> {
244 const cache = new LRUCache<string, Result>({
245 max: maxCacheSize,
246 })
247
248 const memoized = (...args: Args): Result => {
249 const key = cacheFn(...args)
250 const cached = cache.get(key)
251 if (cached !== undefined) {
252 return cached
253 }
254
255 const result = f(...args)
256 cache.set(key, result)
257 return result
258 }
259
260 // Add cache management methods
261 memoized.cache = {
262 clear: () => cache.clear(),
263 size: () => cache.size,
264 delete: (key: string) => cache.delete(key),
265 // peek() avoids updating recency — we only want to observe, not promote
266 get: (key: string) => cache.peek(key),
267 has: (key: string) => cache.has(key),
268 }
269
270 return memoized
271}

Callers 8

windowsPaths.tsFile · 0.85
git.tsFile · 0.85
json.tsFile · 0.85
registry.tsFile · 0.85
parser.tsFile · 0.85
client.tsFile · 0.85

Calls 3

deleteMethod · 0.80
clearMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected