Amazon Vinyl
    Preparing search index...

    Class LruCache<K, V>

    An LRU Cache implementation. An LRU (Least Recently Used) Cache is a Map with a fixed capacity. When the capacity is exceeded, the least recently used element will be removed. An element is considered to be used when it has been retrieved via get, or when it's been set. Iteration does not affect ordering.

    Type Parameters

    • K
    • V

    Implements

    Index
    onEvict: ((element: V, key: K, list: CacheMap<K, V>) => void) | null = null

    When an element is added when at capacity, the least recently used element will be removed. This callback can be set to be notified with the element being evicted, which may be used for disposal.

    onEvicting: ((element: V, key: K, list: CacheMap<K, V>) => boolean) | null = null

    An element is about to be removed. Should return true if the element may be evicted, otherwise false. If false is returned for all elements, an IllegalStateError is thrown.

    • Returns an iterable of key, value pairs for every entry in the map.

      Returns IterableIterator<[K, V]>

    • Executes a provided function once per each key/value pair in the Map, in insertion order.

      Parameters

      • callback: (value: V, key: K, map: this) => void

        A callback to invoke for every element in the cache.

      • OptionalthisArg: any

        Value to use as this when executing callback

      Returns void

    • Returns the mapped value for the given key, and moves the element to the most recently used position.

      Parameters

      • key: K

      Returns V | undefined

      Returns the element associated with the given key, or undefined if no such element exists.

    • Returns an iterable of keys in the map. This will be ordered from least recently used to most.

      Returns IterableIterator<K>

    • Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated and position moved to most recently used.

      Parameters

      • key: K
      • value: V

      Returns this

    • Returns an iterable of values in the map. This will be ordered from least recently used to most.

      Returns IterableIterator<V>