javascript-collections-framework
    Preparing search index...

    Interface LinkedHashMapOptions<K, V>

    Options for a LinkedHashMap. At most one of key and equivalence may be given; with neither, keys compare with SameValueZero, as in native Map. With accessOrder: true and a maxSize, the map is a least-recently-used cache.

    const lru: LinkedHashMapOptions<string, Response> = {
    accessOrder: true,
    maxSize: 100,
    onEvict: (response, url) => console.log('dropped', url),
    }
    interface LinkedHashMapOptions<K, V> {
        accessOrder?: boolean;
        equivalence?: Equivalence<K>;
        key?: KeyOf<K>;
        maxSize?: number;
        onEvict?: (value: V, key: K, map: LinkedHashMap<K, V>) => void;
    }

    Type Parameters

    • K
    • V
    Index
    accessOrder?: boolean

    When true, reading or writing a present key moves its mapping to the end, so the first mapping is the least recently used. Default false: insertion order.

    equivalence?: Equivalence<K>

    Decides key equality by its equals and hash. valueEquivalence honours the equalsSymbol/hashCodeSymbol protocol; sameValueZeroEquivalence is the default behaviour.

    key?: KeyOf<K>

    Derives the primitive key a key is found by; two keys are the same key when their derived keys are SameValueZero-equal. Called once per key per operation, never again for a stored key.

    maxSize?: number

    The most mappings the map keeps: inserting a new key past it removes mappings from the front (never the one just inserted). A positive safe integer; no bound when omitted.

    onEvict?: (value: V, key: K, map: LinkedHashMap<K, V>) => void

    Called as onEvict(value, key, map), with this undefined, once per mapping removed by maxSize, in eviction order, after the call that evicted it has finished its changes.