Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

574 B
Raw Blame
export function memoizeStringResult<T>(
  compute: (key: string) => T,
  maxEntries: number
): (key: string) => T {
  // Box results so undefined and null are cache hits too.
  const cache = new Map<string, { value: T }>()
  return (key: string): T => {
    const cached = cache.get(key)
    if (cached) {
      return cached.value
    }
    const value = compute(key)
    if (cache.size >= maxEntries) {
      const oldest = cache.keys().next()
      if (!oldest.done) {
        cache.delete(oldest.value)
      }
    }
    cache.set(key, { value })
    return value
  }
}