A Map-like class that implements a "Least Recently Used" (LRU) cache policy. When the cache reaches its capacity, the least recently used item is removed.

Type Parameters

  • K
  • V

Hierarchy

  • Map<K, V>
    • MapLru

Constructors

Methods

Constructors

Methods

  • Retrieves the value for a given key and marks it as recently used.

    Parameters

    • key: K

      The key of the element to retrieve.

    Returns undefined | V

    The value associated with the key, or undefined if the key is not in the cache.

  • Adds or updates a key-value pair in the cache and marks the key as recently used. If setting a new key causes the cache to exceed its capacity, the least recently used item is evicted.

    Parameters

    • key: K

      The key of the element to add or update.

    • value: V

      The value of the element to add or update.

    Returns MapLru<K, V>

    The MapLru instance.

  • Removes the specified element from the cache.

    Parameters

    • key: K

      The key of the element to remove.

    Returns boolean

    true if an element in the MapLru object existed and has been removed, or false if the element does not exist.