lru-cache
    Preparing search index...

    Interface Status<K, 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.

    These objects are also the context objects passed to listeners on the lru-cache:metrics diagnostic channel, and the lru-cache tracing channels, in platforms that support them.

    interface Status<K, V> {
        context?: unknown;
        delete?: DisposeReason;
        entrySize?: number;
        fetch?: "get" | "miss" | "hit" | "stale" | "inflight" | "refresh";
        fetchAborted?: true;
        fetchAbortIgnored?: true;
        fetchDispatched?: true;
        fetchError?: Error;
        fetchRejected?: true;
        fetchResolved?: true;
        fetchUpdated?: true;
        forceRefresh?: boolean;
        get?: "miss" | "hit" | "stale" | "fetching" | "stale-fetching";
        has?: "miss" | "hit" | "stale";
        key?: K;
        maxEntrySizeExceeded?: true;
        memo?: "miss" | "hit";
        now?: number;
        oldValue?: V;
        op?: "set" | "delete" | "fetch" | "get" | "memo" | "has" | "peek";
        peek?: "miss" | "hit" | "stale";
        remainingTTL?: number;
        returnedStale?: true;
        set?: "add" | "update" | "replace" | "miss" | "deleted";
        start?: number;
        totalCalculatedSize?: number;
        trace?: boolean;
        ttl?: number;
        value?: V;
    }

    Type Parameters

    • K
    • V
    Index

    Properties

    context?: unknown

    The context option provided to a memo or fetch operation

    In practice, of course, this will be the same type as the FC fetch context param used to instantiate the LRUCache, but the convolutions of threading that through would get quite complicated, and preclude forcing/forbidding the passing of a context param where it is/isn't expected, which is more valuable for error prevention.

    delete?: DisposeReason

    The status of a delete() operation.

    entrySize?: number

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

    fetch?: "get" | "miss" | "hit" | "stale" | "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.
    fetchAborted?: true

    The fetch received an abort signal

    fetchAbortIgnored?: true

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

    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

    forceRefresh?: boolean

    forceRefresh option was used for either a fetch or memo operation

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

    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. If it was returned, then the returnedStale flag will be set.
    • stale-fetching: The value is being fetched in the background, but is currently stale. If the stale value was returned, then the returnedStale flag will be set.
    • 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
    key?: K

    The key that was set or retrieved

    maxEntrySizeExceeded?: true

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

    memo?: "miss" | "hit"

    The status of a memo() operation.

    • 'hit': the item was found in the cache and returned
    • 'miss': the memoMethod function was called
    now?: number

    The timestamp used for TTL calculation

    oldValue?: V

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

    op?: "set" | "delete" | "fetch" | "get" | "memo" | "has" | "peek"

    The operation being performed

    peek?: "miss" | "hit" | "stale"

    The result of a peek() operation

    • hit: the item was found and returned
    • stale: the item is in the cache, but past its ttl and not returned
    • miss: item not in the cache
    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" | "deleted"

    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.

    trace?: boolean

    A tracingChannel trace was started for this operation

    ttl?: number

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

    value?: V

    The value that was set