RTCForge API Reference v1.1.1
    Preparing search index...

    Class MemoryStateStore

    In-process StateStore backed by a Map, with lazy TTL expiration.

    Suitable for single-process deployments and tests. Expired entries are evicted lazily on access (get, has, keys) rather than by a background timer, using the injected Clock to determine the current time. State is not shared across processes. Optionally, a background sweeper (see the constructor's sweepIntervalMs) can proactively purge expired keys so memory is reclaimed even for keys that are never read again.

    const store = new MemoryStateStore()
    await store.set('room:1', { peers: 2 }, 60_000) // expires in 60s
    await store.get<{ peers: number }>('room:1') // { peers: 2 }

    Implements

    Index

    Constructors

    Methods

    Constructors

    • Parameters

      • _clock: Clock = systemClock

        Clock used to evaluate TTL expiration.

      • OptionalsweepIntervalMs: number

        When set (> 0), a background timer proactively purges expired entries every this-many milliseconds, reclaiming memory for keys that are never accessed again. Omit to disable (the default): expiry then stays purely lazy via get/has/keys. The timer is unref'd where supported so it never keeps a Node process alive.

      Returns MemoryStateStore

      systemClock

    Methods

    • Reads the value stored at key.

      Type Parameters

      • T

        Expected type of the stored value.

      Parameters

      • key: string

        The key to read.

      Returns Promise<T | undefined>

      The stored value, or undefined if the key is absent or expired.

    • Reports whether a live (non-expired) entry exists at key.

      Parameters

      • key: string

        The key to test.

      Returns Promise<boolean>

      true if a non-expired value is present.

    • Lists the keys of all live entries, optionally filtered by prefix.

      Parameters

      • Optionalprefix: string

        When provided, only keys starting with this string are returned.

      Returns Promise<string[]>

      The matching keys.

    • Writes a value at key, optionally with a TTL after which it expires.

      Type Parameters

      • T

        Type of the value being stored.

      Parameters

      • key: string

        The key to write.

      • value: T

        The value to store.

      • OptionalttlMs: number

        Optional lifetime in milliseconds; if omitted the entry never expires.

      Returns Promise<void>