Class LRUCache<K, V>

A LRU cache intended for caching pure functions.

Type Parameters

  • K

    The type of the key.

  • V

    The type of the value.

Constructors

Properties

Accessors

Methods

Constructors

  • Constructs a new instance of the LRUCache class.

    Type Parameters

    • K
    • V

    Parameters

    • maxSize: number

      The maximum size for this cache. We recommend setting this to be one less than a power of 2, as most hashtables - including V8's Object hashtable (https://crsrc.org/c/v8/src/objects/ordered-hash-table.cc)

      • uses powers of two for hashtable sizes. It can't exactly be a power of two, as a .set() call could temporarily set the size of the map to be maxSize + 1.

    Returns LRUCache<K, V>

Properties

maxSize: number

The maximum size of the cache.

Accessors

Methods

  • Gets the specified key from the cache, or undefined if it is not in the cache.

    Parameters

    • key: K

      The key to get.

    Returns undefined | V

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

  • Sets an entry in the cache.

    Parameters

    • key: K

      The key of the entry.

    • value: V

      The value of the entry.

    Returns void

    Error, if the map already contains the key.