Session stores are responsible for creating, retrieving, persisting, and expiringDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/binary-person/rammerhead/llms.txt
Use this file to discover all available pages before exploring further.
RammerheadSession objects. All stores implement the RammerheadSessionAbstractStore interface. Choose RammerheadSessionFileCache for production deployments that need sessions to survive restarts, and RammerheadSessionMemoryStore for development or stateless environments.
RammerheadSessionAbstractStore
The abstract base class that all session stores extend. It cannot be instantiated directly. Concrete stores must implementkeys, has, get, add, delete, and addSerializedSession.
Methods
attachToProxy
RammerheadProxy instance by setting proxy.openSessions = this. Call this once after constructing both the proxy and the store.
The proxy instance to attach to.
When
true, all sessions currently tracked by proxy.openSessions are closed before the store takes over.keys
Array of all session IDs currently tracked by the store.
has
Session ID to check.
true if the session exists in the store.get
Session ID to retrieve.
When
true, calls session.updateLastUsed() before returning.The session, or
undefined if it does not exist.add
Unique ID for the new session.
The newly created session.
delete
ID of the session to remove.
true if the session existed and was deleted.addSerializedSession
session.serializeSession().
ID to assign to the imported session.
JSON string from
RammerheadSession.serializeSession().close
RammerheadSessionFileCache overrides this to flush in-memory sessions to disk before shutdown. RammerheadSessionMemoryStore does not implement it.
RammerheadSessionFileCache
ExtendsRammerheadSessionAbstractStore with disk persistence. Active sessions are kept in a memory cache for fast access. Idle sessions are serialized to .rhfsession files on disk and reloaded on demand. A background interval periodically removes sessions that exceed staleTimeout or maxToLive.
This is the recommended store for production deployments.
Constructor
Directory where session files are stored. The directory must already exist.
Logger instance for store operations.
Milliseconds of inactivity after which an in-memory session is flushed to disk. Default is 20 minutes (
1000 * 60 * 20).How often (in milliseconds) the background interval checks for sessions to flush. Default is 10 minutes (
1000 * 60 * 10).When
true, sessions that were never used (i.e. lastUsed === createdAt) are deleted instead of being written to disk during a cache flush.When
true, session files that fail JSON parsing are automatically deleted and a warning is logged. This happens when Node exits abruptly while writing a session file.Configuration for the background stale-session cleanup. Set to
null to disable stale cleanup entirely. The class constructor defaults to staleTimeout: 1 day, maxToLive: 4 days, staleCheckInterval: 1 hour. The built-in server (src/config.js) overrides these to staleTimeout: 3 days, maxToLive: null, staleCheckInterval: 6 hours.RammerheadSessionMemoryStore
ExtendsRammerheadSessionAbstractStore with a purely in-memory Map. All sessions are lost when the process exits. A background interval removes sessions that exceed staleTimeout or maxToLive.
Use RammerheadSessionMemoryStore during development, in single-request test environments, or when session persistence is explicitly not required.
Constructor
Logger instance for store operations.
Milliseconds of inactivity after which a session is deleted. Default is 30 minutes (
1000 * 60 * 30). Set to null to disable.Maximum session lifetime in milliseconds regardless of activity. Default is 4 hours (
1000 * 60 * 60 * 4). Set to null to disable.How often (in milliseconds) the background cleanup interval runs. Default is 1 minute.
Usage examples
- FileCache
- MemoryStore