Class LRUCache<K, V, FC>

Default export, the thing you're using this module to get.

All properties from the options object (with the exception of OptionsBase.max and OptionsBase.maxSize) are added as normal public members. (max and maxBase are read-only getters.) Changing any of these will alter the defaults for subsequent method calls, but is otherwise safe.

Type Parameters

  • K extends {}

  • V extends {}

  • FC = unknown

Hierarchy

  • LRUCache

Implements

  • Map<K, V>

Constructors

Properties

#addItemSize: ((index, size, status?) => void) = ...

Type declaration

    • (index, size, status?): void
    • Parameters

      Returns void

#calculatedSize: number
#dispose?: Disposer<K, V>
#disposeAfter?: Disposer<K, V>
#disposed?: DisposeTask<K, V>[]
#fetchMethod?: Fetcher<K, V, FC>
#free: StackLike
#hasDispose: boolean
#hasDisposeAfter: boolean
#hasFetchMethod: boolean
#head: Index
#isStale: ((index) => boolean) = ...

Type declaration

    • (index): boolean
    • Parameters

      Returns boolean

#keyList: (undefined | K)[]
#keyMap: Map<K, Index>
#max: number
#maxSize: number
#removeItemSize: ((index) => void) = ...

Type declaration

    • (index): void
    • Parameters

      Returns void

#requireSize: ((k, v, size?, sizeCalculation?) => number) = ...

Type declaration

    • (k, v, size?, sizeCalculation?): number
    • Parameters

      Returns number

#setItemTTL: ((index, ttl, start?) => void) = ...

Type declaration

    • (index, ttl, start?): void
    • Parameters

      • index: Index
      • ttl: number
      • Optional start: number

      Returns void

#size: number
#sizes?: ZeroArray
#starts?: ZeroArray
#statusTTL: ((status, index) => void) = ...

Type declaration

    • (status, index): void
    • Parameters

      Returns void

#tail: Index
#ttls?: ZeroArray
#updateItemAge: ((index) => void) = ...

Type declaration

    • (index): void
    • Parameters

      Returns void

#valList: (undefined | V | BackgroundFetch<V>)[]
[toStringTag]: string = 'LRUCache'

A String value that is used in the creation of the default string description of an object. Called by the built-in method Object.prototype.toString.

allowStale: boolean
allowStaleOnFetchAbort: boolean
allowStaleOnFetchRejection: boolean
ignoreFetchAbort: boolean
maxEntrySize: number
noDeleteOnFetchRejection: boolean
noDeleteOnStaleGet: boolean
noDisposeOnSet: boolean
noUpdateTTL: boolean
sizeCalculation?: SizeCalculator<K, V>
ttl: number
ttlAutopurge: boolean
ttlResolution: number
updateAgeOnGet: boolean
updateAgeOnHas: boolean

Accessors

  • get calculatedSize(): number
  • The total computed size of items in the cache (read-only)

    Returns number

  • get size(): number
  • The number of items stored in the cache (read-only)

    Returns number

Methods

  • Parameters

    • __namedParameters: {
          allowStale: undefined | boolean;
      } = {}
      • allowStale: undefined | boolean

    Returns Generator<Index, void, unknown>

  • Parameters

    • __namedParameters: {
          allowStale: undefined | boolean;
      } = {}
      • allowStale: undefined | boolean

    Returns Generator<Index, void, unknown>

  • Iterating over the cache itself yields the same results as LRUCache.entries

    Returns Generator<[K, V], void, unknown>

  • Clear the cache entirely, throwing away all values.

    Returns void

  • Deletes a key out of the cache. Returns true if the key was deleted, false otherwise.

    Parameters

    • k: K

    Returns boolean

  • Return a generator yielding [key, value] pairs, in order from most recently used to least recently used.

    Returns Generator<[K, V], void, unknown>

  • Find a value for which the supplied fn method returns a truthy value, similar to Array.find(). fn is called as fn(value, key, cache).

    Parameters

    • fn: ((v, k, self) => boolean)
        • (v, k, self): boolean
        • Parameters

          Returns boolean

    • getOptions: GetOptions<K, V, FC> = {}

    Returns undefined | V

  • Call the supplied function on each item in the cache, in order from most recently used to least recently used. fn is called as fn(value, key, cache). Does not update age or recenty of use. Does not iterate over stale values.

    Parameters

    • fn: ((v, k, self) => any)
        • (v, k, self): any
        • Parameters

          Returns any

    • thisp: any = ...

    Returns void

  • Return a value from the cache. Will update the recency of the cache entry found.

    If the key is not found, get() will return undefined.

    Parameters

    Returns undefined | V

  • Return the remaining TTL time for a given entry key

    Parameters

    • key: K

    Returns number

  • Check if a key is in the cache, without updating the recency of use. Will return false if the item is stale, even though it is technically in the cache.

    Will not update item age unless LRUCache.OptionsBase.updateAgeOnHas is set.

    Parameters

    Returns boolean

  • Get the extended info about a given entry, to get its value, size, and TTL info simultaneously. Like LRUCache#dump, but just for a single key. Always returns stale values, if their info is found in the cache, so be sure to check for expired TTLs if relevant.

    Parameters

    • key: K

    Returns undefined | Entry<V>

  • Return a generator yielding the keys in the cache, in order from most recently used to least recently used.

    Returns Generator<K, void, unknown>

  • Reset the cache and load in the items in entries in the order listed. Note that the shape of the resulting cache may be different if the same options are not used in both caches.

    Parameters

    Returns void

  • Evict the least recently used item, returning its value or undefined if cache is empty.

    Returns undefined | V

  • Delete any stale entries. Returns true if anything was removed, false otherwise.

    Returns boolean

  • Inverse order version of LRUCache.entries

    Return a generator yielding [key, value] pairs, in order from least recently used to most recently used.

    Returns Generator<(undefined | K | V | BackgroundFetch<V>)[], void, unknown>

  • The same as LRUCache.forEach but items are iterated over in reverse order. (ie, less recently used items are iterated over first.)

    Parameters

    • fn: ((v, k, self) => any)
        • (v, k, self): any
        • Parameters

          Returns any

    • thisp: any = ...

    Returns void

  • Inverse order version of LRUCache.keys

    Return a generator yielding the keys in the cache, in order from least recently used to most recently used.

    Returns Generator<K, void, unknown>

  • Inverse order version of LRUCache.values

    Return a generator yielding the values in the cache, in order from least recently used to most recently used.

    Returns Generator<undefined | V | BackgroundFetch<V>, void, unknown>

  • Return a generator yielding the values in the cache, in order from most recently used to least recently used.

    Returns Generator<V, void, unknown>

  • Internal

    Do not call this method unless you need to inspect the inner workings of the cache. If anything returned by this object is modified in any way, strange breakage may occur.

    These fields are private for a reason!

    Type Parameters

    • K extends {}

    • V extends {}

    • FC extends unknown = unknown

    Parameters

    Returns {
        backgroundFetch: ((k, index, options, context) => BackgroundFetch<V>);
        free: StackLike;
        indexes: ((options?) => Generator<Index, void, unknown>);
        isBackgroundFetch: ((p) => boolean);
        isStale: ((index) => boolean);
        keyList: (undefined | K)[];
        keyMap: Map<K, number>;
        moveToTail: ((index) => void);
        next: NumberArray;
        prev: NumberArray;
        rindexes: ((options?) => Generator<Index, void, unknown>);
        sizes: undefined | ZeroArray;
        starts: undefined | ZeroArray;
        ttls: undefined | ZeroArray;
        valList: (undefined | V | BackgroundFetch<V>)[];
        get head(): Index;
        get tail(): Index;
    }

    • backgroundFetch: ((k, index, options, context) => BackgroundFetch<V>)
    • free: StackLike
    • indexes: ((options?) => Generator<Index, void, unknown>)
        • (options?): Generator<Index, void, unknown>
        • Parameters

          • Optional options: {
                allowStale: boolean;
            }
            • allowStale: boolean

          Returns Generator<Index, void, unknown>

    • isBackgroundFetch: ((p) => boolean)
        • (p): boolean
        • Parameters

          • p: any

          Returns boolean

    • isStale: ((index) => boolean)
        • (index): boolean
        • Parameters

          • index: undefined | number

          Returns boolean

    • keyList: (undefined | K)[]
    • keyMap: Map<K, number>
    • moveToTail: ((index) => void)
        • (index): void
        • Parameters

          • index: number

          Returns void

    • next: NumberArray
    • prev: NumberArray
    • rindexes: ((options?) => Generator<Index, void, unknown>)
        • (options?): Generator<Index, void, unknown>
        • Parameters

          • Optional options: {
                allowStale: boolean;
            }
            • allowStale: boolean

          Returns Generator<Index, void, unknown>

    • sizes: undefined | ZeroArray
    • starts: undefined | ZeroArray
    • ttls: undefined | ZeroArray
    • valList: (undefined | V | BackgroundFetch<V>)[]
    • get head(): Index
    • get tail(): Index

Generated using TypeDoc