Member Junction
    Preparing search index...

    Class MJLruCache<K, V>

    Bounded LRU cache with optional TTL — designed to replace the unbounded Map fields that proliferate across MJ singletons (per-credential SDK client caches, issuer caches, script caches, etc.). Built on Map's preserved insertion order: touching an entry deletes-and-reinserts to move it to the end, so eviction is trivially the first key.

    • Get returns undefined for missing or expired entries and lazily evicts expired ones (firing onEvict once).
    • Set updates an existing entry in place (resetting recency + TTL) or evicts the least-recently-used when size === maxSize.
    • onEvict is called for every removal — overflow, expiry, explicit delete, or Clear() — so callers can release SDK clients, sockets, etc.

    Thread-safety: same single-threaded JS guarantees as Map. Not safe across worker threads — pin one cache per worker.

    NOTE: this is intentionally minimal. We don't expose keys()/values() iterators because LRU semantics interact poorly with iteration order — callers who need those should use Map directly.

    Type Parameters

    • K
    • V
    Index

    Constructors

    Accessors

    Methods

    Constructors

    Accessors

    • get MaxSize(): number

      Configured maximum entry count. Read-only after construction.

      Returns number

    • get Size(): number

      Current entry count (including any expired entries that haven't been lazily evicted yet — call Prune() to force eviction first).

      Returns number

    Methods

    • Remove every entry, firing onEvict for each with reason 'clear'.

      Returns void

    • Remove a key. Returns true if removed. Fires onEvict with reason 'delete'.

      Parameters

      • key: K

      Returns boolean

    • Look up a value, refreshing its recency. Returns undefined if the key is absent or the entry has expired. Expired entries are evicted lazily on the miss (firing onEvict with reason 'ttl').

      Parameters

      • key: K

      Returns V | undefined

    • Whether the key is present and unexpired. Does not refresh recency.

      Parameters

      • key: K

      Returns boolean

    • Eagerly evict all expired entries. Useful from a periodic timer when lazy eviction (only on Get/Has) isn't sufficient — for example, when entries hold expensive resources you want released even if no one reads them again.

      Returns number

    • Insert or replace an entry. If replacing, the old value is evicted with reason 'delete' so SDK-client style resources can be cleaned up. If inserting and the cache is full, the LRU entry is evicted with reason 'lru'.

      Parameters

      • key: K
      • value: V

      Returns void