FileSessionStore class

A dart:io file-system backed session snapshot store.

Snapshots are stored as flat JSON files keyed by their snapshotId, under an optional per-tenant sub-directory prefix:

dirPath/<prefix>/<snapshotId>.json

getSnapshot(sessionId: ...) resolves the session's current leaf via a tiny per-session pointer file (<prefix>/.pointers/<sessionId>.json, see _PointerDoc) - one pointer read plus one snapshot read. When the pointer is missing (e.g. a legacy store) or stale it transparently falls back to scanning the prefix directory and selecting the single leaf whose sessionId matches, then rewrites the pointer so subsequent lookups are fast again.

Implemented types
Annotations
  • @experimental

Constructors

FileSessionStore(String dirPath, {int? maxPersistedChainLength, String snapshotPathPrefix(Map<String, dynamic>? context)?, bool rejectBranchingSessions = false, Duration snapshotWatchPollInterval = _defaultSnapshotWatchPollInterval})
Creates a file-backed store rooted at dirPath (created if missing).

Properties

hashCode int
The hash code for this object.
no setterinherited
maxPersistedChainLength int?
When set, a chain longer than this is trimmed (oldest first) on each save.
final
rejectBranchingSessions bool
Whether a branched sessionId lookup is rejected instead of resolving to the most-recent leaf.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
snapshotPathPrefix String Function(Map<String, dynamic>? context)?
Derives the per-tenant sub-directory prefix from the call's context.
final

Methods

getLatestSnapshotMetadata(String sessionId, {Map<String, dynamic>? context}) Future<SessionSnapshot?>
SessionStore.getSnapshot by sessionId (the session's latest leaf) without the state: the same resolution, the same null-if-none contract, and a row with state null. The resolved sessionId is carried on the returned row even for a row that stored it only under state.
override
getSnapshot({String? snapshotId, String? sessionId, Map<String, dynamic>? context}) Future<SessionSnapshot?>
Loads a snapshot either by its snapshotId or by sessionId.
override
getSnapshotMetadata(String snapshotId, {Map<String, dynamic>? context}) Future<SessionSnapshot?>
SessionStore.getSnapshot by snapshotId without the state: the returned row carries every other field as stored, with state null, and the same null-if-not-found contract.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onSnapshotStateChange(String snapshotId, void callback(SessionSnapshot snapshot), {Map<String, dynamic>? context}) → void Function()?
Watches a single snapshot file for changes and invokes callback with the parsed snapshot whenever it changes.
override
saveSnapshot(String? snapshotId, SnapshotMutator mutator, {Map<String, dynamic>? context}) Future<String?>
Atomically reads the current snapshot (if snapshotId is provided), passes it to mutator, and persists the result.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited