tvmjs
    Preparing search index...

    Class LRUCache<K, V>

    A generic LRU (Least Recently Used) cache with bounded size.

    Entries are evicted in insertion order when the cache exceeds maxSize. Uses a Map to maintain insertion order for O(1) LRU eviction.

    Type Parameters

    • K

      Cache key type.

    • V

      Cache value type.

    Index

    Constructors

    Accessors

    Methods

    Constructors

    • Type Parameters

      • K

        Cache key type.

      • V

        Cache value type.

      Parameters

      • maxSize: number
      • OptionalonEvict: (key: K, value: V) => void

      Returns LRUCache<K, V>

    Accessors

    • get size(): number

      Number of entries currently in the cache.

      Returns number

    Methods

    • Get a value from the cache, constructing it via constructor on miss.

      On hit: moves the entry to most-recently-used position and returns it. On miss: calls constructor() to create the value, inserts it, and returns it. If the cache is full, the least-recently-used entry is evicted first.

      Parameters

      • key: K

        The cache key.

      • constructor: () => V

        Factory function called on cache miss to produce the value.

      Returns V

      The cached or newly constructed value.

    • Clear all cached entries.

      Does not dispose values — the caller is responsible for cleanup (e.g. destroying GPU buffers) before calling invalidate.

      Returns void

    • Check whether eviction would be needed for a new entry.

      Useful when the caller needs to perform side effects before eviction (e.g. flushing pending GPU commands before destroying an evicted buffer).

      Parameters

      • key: K

        The key to check.

      Returns boolean

      true if inserting key would trigger eviction of another entry.

    • Iterate over all cached values (for disposal).

      Returns IterableIterator<V>