Interface Status<V>

Occasionally, it may be useful to track the internal behavior of the cache, particularly for logging, debugging, or for behavior within the fetchMethod. To do this, you can pass a status object to the LRUCache#fetch, LRUCache#get, LRUCache#set, LRUCache#memo, and LRUCache#has methods.

The status option should be a plain JavaScript object. The following fields will be set on it appropriately, depending on the situation.

interface Status<V> {
    entrySize?: number;
    fetch?:
        | "miss"
        | "hit"
        | "stale"
        | "get"
        | "inflight"
        | "refresh";
    fetchAbortIgnored?: true;
    fetchAborted?: true;
    fetchDispatched?: true;
    fetchError?: Error;
    fetchRejected?: true;
    fetchResolved?: true;
    fetchUpdated?: true;
    get?: "miss" | "hit" | "stale";
    has?: "miss" | "hit" | "stale";
    maxEntrySizeExceeded?: true;
    now?: number;
    oldValue?: V;
    remainingTTL?: number;
    returnedStale?: true;
    set?:
        | "add"
        | "update"
        | "replace"
        | "miss";
    start?: number;
    totalCalculatedSize?: number;
    ttl?: number;
}

Type Parameters

  • V

Properties

entrySize?: number

The calculated size for the item, if sizes are used.

fetch?:
    | "miss"
    | "hit"
    | "stale"
    | "get"
    | "inflight"
    | "refresh"

The status of a LRUCache#fetch operation. Note that this can change as the underlying fetch() moves through various states.

  • inflight: there is another fetch() for this key which is in process
  • get: there is no OptionsBase.fetchMethod, so LRUCache#get was called.
  • miss: the item is not in cache, and will be fetched.
  • hit: the item is in the cache, and was resolved immediately.
  • stale: the item is in the cache, but stale.
  • refresh: the item is in the cache, and not stale, but FetchOptions.forceRefresh was specified.
fetchAbortIgnored?: true

The abort signal received was ignored, and the fetch was allowed to continue.

fetchAborted?: true

The fetch received an abort signal

fetchDispatched?: true

The OptionsBase.fetchMethod was called

fetchError?: Error

The reason for a fetch() rejection. Either the error raised by the OptionsBase.fetchMethod, or the reason for an AbortSignal.

fetchRejected?: true

The fetchMethod promise was rejected

fetchResolved?: true

The fetchMethod promise resolved successfully

fetchUpdated?: true

The cached value was updated after a successful call to OptionsBase.fetchMethod

get?: "miss" | "hit" | "stale"

The status of a LRUCache#get operation.

  • fetching: The item is currently being fetched. If a previous value is present and allowed, that will be returned.
  • stale: The item is in the cache, and is stale.
  • hit: the item is in the cache
  • miss: the item is not in the cache
has?: "miss" | "hit" | "stale"

The results of a LRUCache#has operation

  • hit: the item was found in the cache
  • stale: the item was found in the cache, but is stale
  • miss: the item was not found in the cache
maxEntrySizeExceeded?: true

A flag indicating that the item was not stored, due to exceeding the OptionsBase.maxEntrySize

now?: number

The timestamp used for TTL calculation

oldValue?: V

The old value, specified in the case of set:'update' or set:'replace'

remainingTTL?: number

the remaining ttl for the item, or undefined if ttls are not used.

returnedStale?: true

A fetch or get operation returned a stale value.

set?:
    | "add"
    | "update"
    | "replace"
    | "miss"

The status of a set() operation.

  • add: the item was not found in the cache, and was added
  • update: the item was in the cache, with the same value provided
  • replace: the item was in the cache, and replaced
  • miss: the item was not added to the cache for some reason
start?: number

the start time for the item, or undefined if ttls are not used.

totalCalculatedSize?: number

The total calculated size of the cache, if sizes are used.

ttl?: number

the ttl stored for the item, or undefined if ttls are not used.