Interface LRUCacheOptions<TKey, TValue>

Type Parameters

  • TKey

  • TValue

Hierarchy

  • LRUCacheOptions

Properties

clone?: boolean

Clone values being set and fetched from the cache (clones on set and any retrievals). Useful to maintain immutability. NOTE! This does come with performance overhead (almost twice as slow). Defaults to false.

cloneFn?: ((value: TValue) => TValue)

Type declaration

    • (value: TValue): TValue
    • Custom function to be used with the clone option. If not passed, JSON.parse(JSON.stringify(value)) is used for cloning objects.

      Parameters

      • value: TValue

      Returns TValue

entryExpirationTimeInMS?: null | number

The time to live for cache entries. Setting this to null will make entries never expire. Default value is null.

maxSize?: number

The max number of items the cache can hold. Once the cache reaches this number, the least recently used entries will start to be evicted to make room for new entries. Defaults to 25.

onEntryEvicted?: ((evictedEntry: { isExpired: boolean; key: TKey; value: TValue }) => void)

Type declaration

    • (evictedEntry: { isExpired: boolean; key: TKey; value: TValue }): void
    • Function to be called whenever an entry is evicted from the cache (when evicted due to needing to make room, is expired, or deleted using delete()). Passed argument is an object:

      {
      key: TKey;
      value: TValue;
      isExpired: boolean;
      }

      Parameters

      • evictedEntry: { isExpired: boolean; key: TKey; value: TValue }
        • isExpired: boolean
        • key: TKey
        • value: TValue

      Returns void

onEntryMarkedAsMostRecentlyUsed?: ((entry: { key: TKey; value: TValue }) => void)

Type declaration

    • (entry: { key: TKey; value: TValue }): void
    • Function to be called whenever an entry is marked as recently used (on set, get, find, etc). Passed argument is an object:

      {
      key: TKey;
      value: TValue;
      }

      Parameters

      • entry: { key: TKey; value: TValue }
        • key: TKey
        • value: TValue

      Returns void

Generated using TypeDoc