Library API
    Preparing search index...

    Class BoundedCache<K, V>

    High-performance Map implementation enforcing maximum capacity (LRU) and TTL eviction. Supports static keys (immortal glossary definitions) and date-salt staleness purging.

    Type Parameters

    • K = string
    • V = string

    Hierarchy

    • Map<K, V>
      • BoundedCache
    Index
    • Creates a bounded cache with configurable capacity and entry lifetime.

      Type Parameters

      • K = string
      • V = string

      Parameters

      • maxSize: number = 1000

        Maximum number of non-static entries retained

      • ttl: number = ...

        Default time-to-live for entries in milliseconds

      Returns BoundedCache<K, V>

    "[toStringTag]": string
    maxSize: number
    ttl: number
    "[species]": MapConstructor
    • Purges cache entries. If count is specified, evicts up to count oldest non-static entries. If omitted, clears all entries, including static entries.

      Parameters

      • Optionalcount: number

        Optional number of entries to evict. If omitted, clears all entries.

      Returns void

    • Deletes a key from the cache, removing its expiration and static key markers.

      Parameters

      • key: K

        The cache key to delete

      Returns boolean

      True if the key was deleted, false if it did not exist

    • Deletes all cache entries whose keys start with the specified prefix. The prefix comparison is case-insensitive.

      Parameters

      • prefix: string

        The prefix string to match against cache keys

      Returns number

      The number of entries deleted

    • Executes a callback for each cache entry after evicting expired entries.

      Parameters

      • callbackfn: (value: V, key: K, map: Map<K, V>) => void

        Function to execute for each entry

      • OptionalthisArg: any

        Optional value to use as this when executing the callback

      Returns void

    • Retrieves a value from the cache by key. Evaluates TTL expiration via #expires specifically for the requested key, and updates LRU ordering by deleting and re-inserting the key in the underlying Map. Leaves the expiration deadline unchanged.

      Parameters

      • key: K

        The cache key to retrieve

      Returns V | undefined

      The cached value, or undefined if not found or expired

    • Returns a specified element from the Map object. If no element is associated with the specified key, a new element with the value defaultValue will be inserted into the Map and returned.

      Parameters

      • key: K
      • defaultValue: V

      Returns V

      The element associated with the specified key, which will be defaultValue if no element previously existed.

    • Returns a specified element from the Map object. If no element is associated with the specified key, the result of passing the specified key to the callback function will be inserted into the Map and returned.

      Parameters

      • key: K
      • callback: (key: K) => V

      Returns V

      The element associated with the specific key, which will be the newly computed value if no element previously existed.

    • Checks if a key exists in the cache and is not expired. Automatically evicts expired entries on access.

      Parameters

      • key: K

        The cache key to check

      Returns boolean

      True if the key exists and is not expired, false otherwise

    • Sets a key-value pair in the cache, enforcing LRU eviction. If finite-TTL is configured, entries retain their original absolute expiration deadline unless an explicit ttl override is passed. If the cache exceeds maxSize, the oldest non-static entry is removed.

      Parameters

      • key: K

        The cache key to set

      • value: V

        The value to store

      • Optionalttl: number

        Optional custom time-to-live in milliseconds for this specific entry

      Returns this

      This cache instance for chaining

    • Returns a plain key-value object of all active non-expired cache entries. Filters out non-string keys to prevent lossy key conversions or collisions (e.g. numeric 1 vs string "1").

      Returns Record<string, V>

    • Creates a BoundedCache from an iterable of key-value pairs.

      Type Parameters

      • K = string
      • V = string

      Parameters

      • entries: Iterable<readonly [K, V]>

        Iterable of [key, value] pairs to populate the cache

      • maxSize: number = 1000

        Maximum number of entries (default: 1000)

      • ttl: number = ...

        Time-to-live in milliseconds (default: 24 hours)

      Returns BoundedCache<K, V>

      A new BoundedCache instance

    • Groups members of an iterable according to the return value of the passed callback.

      Type Parameters

      • K
      • T

      Parameters

      • items: Iterable<T>

        An iterable.

      • keySelector: (item: T, index: number) => K

        A callback which will be invoked for each item in items.

      Returns Map<K, T[]>