@kkdev92/vscode-ext-kit - v4.1.1
    Preparing search index...

    Function getOrCreateCached

    • Reads key from cache, creating and storing it on a miss.

      Bounded as a true LRU: at limit, only the single least-recently-used entry is evicted, and reading an existing key promotes it by re-inserting it. Exported because the same eviction logic is useful for a consumer's own caches.

      Type Parameters

      • T

      Parameters

      • cache: Map<string, T>
      • key: string
      • limit: number
      • create: () => T

      Returns T

      const cache = new Map<string, Expensive>();
      const value = getOrCreateCached(cache, 'key', 100, () => new Expensive());