Interface SetOptions<K, V, FC>

Options that may be passed to the LRUCache#set method.

interface SetOptions<K, V, FC> {
    noDisposeOnSet?: boolean;
    noUpdateTTL?: boolean;
    size?: number;
    sizeCalculation?: SizeCalculator<K, V>;
    start?: number;
    status?: Status<V>;
    ttl?: number;
}

Type Parameters

  • K
  • V
  • FC

Hierarchy

  • Pick<OptionsBase<K, V, FC>,
        | "sizeCalculation"
        | "ttl"
        | "noDisposeOnSet"
        | "noUpdateTTL">
    • SetOptions

Properties

noDisposeOnSet?: boolean

Set to true to suppress calling the OptionsBase.dispose function if the entry key is still accessible within the cache.

This may be overridden by passing an options object to LRUCache#set.

Only relevant if dispose or disposeAfter are set.

noUpdateTTL?: boolean

Boolean flag to tell the cache to not update the TTL when setting a new value for an existing key (ie, when updating a value rather than inserting a new value). Note that the TTL value is always set (if provided) when adding a new entry into the cache.

Has no effect if a OptionsBase.ttl is not set.

May be passed as an option to LRUCache#set.

size?: number

If size tracking is enabled, then setting an explicit size in the LRUCache#set call will prevent calling the OptionsBase.sizeCalculation function.

sizeCalculation?: SizeCalculator<K, V>

A function that returns a number indicating the item's size.

Requires OptionsBase.maxSize to be set.

If not provided, and OptionsBase.maxSize or OptionsBase.maxEntrySize are set, then all LRUCache#set calls must provide an explicit SetOptions.size or sizeCalculation param.

start?: number

If TTL tracking is enabled, then setting an explicit start time in the LRUCache#set call will override the default time from performance.now() or Date.now().

Note that it must be a valid value for whichever time-tracking method is in use.

status?: Status<V>
ttl?: number

Max time in milliseconds for items to live in cache before they are considered stale. Note that stale items are NOT preemptively removed by default, and MAY live in the cache, contributing to its LRU max, long after they have expired, unless OptionsBase.ttlAutopurge is set.

If set to 0 (the default value), then that means "do not track TTL", not "expire immediately".

Also, as this cache is optimized for LRU/MRU operations, some of the staleness/TTL checks will reduce performance, as they will incur overhead by deleting items.

This is not primarily a TTL cache, and does not make strong TTL guarantees. There is no pre-emptive pruning of expired items, but you may set a TTL on the cache, and it will treat expired items as missing when they are fetched, and delete them.

Optional, but must be a non-negative integer in ms if specified.

This may be overridden by passing an options object to cache.set().

At least one of max, maxSize, or TTL is required. This must be a positive integer if set.

Even if ttl tracking is enabled, it is strongly recommended to set a max to prevent unbounded growth of the cache.

If ttl tracking is enabled, and max and maxSize are not set, and ttlAutopurge is not set, then a warning will be emitted cautioning about the potential for unbounded memory consumption. (The TypeScript definitions will also discourage this.)