TS-Scribe - v1.2.0
    Preparing search index...

    Type Alias MemoizeOptions<Args>

    Options for configuring the memoize function.

    type MemoizeOptions<Args extends unknown[]> = {
        cacheErrors?: boolean;
        enableStats?: boolean;
        keyResolver?: (...args: Args) => string;
        maxEntrySize?: number;
        maxSize?: number;
        ttl?: number;
    }

    Type Parameters

    • Args extends unknown[]
    Index

    Properties

    cacheErrors?: boolean

    If true, errors thrown by the function will be cached and re-thrown. If false (default), errors will not be cached and the function will be re-executed on subsequent calls.

    enableStats?: boolean

    Enable cache statistics tracking (hits, misses, evictions).

    false
    
    keyResolver?: (...args: Args) => string

    Custom function to generate cache keys from function arguments. If not provided, a safe JSON.stringify is used.

    Type Declaration

      • (...args: Args): string
      • Parameters

        • ...args: Args

          The arguments passed to the memoized function.

        Returns string

        A string key for the cache.

    maxEntrySize?: number

    Maximum size in bytes for a single cache entry. Prevents memory bombs. If not provided, no size limit is enforced.

    undefined
    
    maxSize?: number

    Maximum number of cache entries. When exceeded, the oldest entry is removed. If not provided, cache size is unlimited.

    Eviction uses an approximate LRU strategy for performance. Access order is only updated when the cache is at or above 90 % of maxSize. Below that threshold, entries are evicted in insertion order (FIFO), not true least-recently-used order. This is a deliberate trade-off: avoid paying the cost of a Map re-insert on every cache hit when the cache still has plenty of headroom.

    If your workload has a small working set relative to maxSize and strict LRU ordering matters, set maxSize closer to the number of distinct argument combinations you expect.

    ttl?: number

    Time in milliseconds after which a cached result expires. If not provided, cached results never expire.