Clock used to evaluate TTL expiration.
OptionalsweepIntervalMs: numberWhen 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.
Removes the entry at key, if any.
The key to delete.
Reads the value stored at key.
Expected type of the stored value.
The key to read.
The stored value, or undefined if the key is absent or expired.
Reports whether a live (non-expired) entry exists at key.
The key to test.
true if a non-expired value is present.
Lists the keys of all live entries, optionally filtered by prefix.
Optionalprefix: stringWhen provided, only keys starting with this string are returned.
The matching keys.
Writes a value at key, optionally with a TTL after which it expires.
Type of the value being stored.
The key to write.
The value to store.
OptionalttlMs: numberOptional lifetime in milliseconds; if omitted the entry never expires.
Stops the background TTL sweeper (if one was started). Idempotent.
In-process StateStore backed by a
Map, with lazy TTL expiration.Remarks
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'ssweepIntervalMs) can proactively purge expired keys so memory is reclaimed even for keys that are never read again.Example