FileSessionStore constructor

FileSessionStore(
  1. String dirPath, {
  2. int? maxPersistedChainLength,
  3. String snapshotPathPrefix(
    1. Map<String, dynamic>? context
    )?,
  4. bool rejectBranchingSessions = false,
  5. Duration snapshotWatchPollInterval = _defaultSnapshotWatchPollInterval,
})

Creates a file-backed store rooted at dirPath (created if missing).

  • maxPersistedChainLength: when set, snapshots older than this many entries in a chain are automatically deleted on each save.
  • snapshotPathPrefix: returns a sub-directory prefix derived from the call's context (e.g. the authenticated user id), useful for multi-tenant isolation: all reads and writes are scoped to that prefix, so one tenant can never see another's snapshots. Defaults to "global".
  • rejectBranchingSessions: when true, a sessionId lookup that resolves to a branched history (more than one leaf) throws StatusCodes.FAILED_PRECONDITION instead of returning the latest leaf. Defaults to false; opt in (e.g. in dev) to surface accidental branching early.
  • snapshotWatchPollInterval: polling interval for the onSnapshotStateChange fallback that backstops the directory watcher (which can miss events on some filesystems, e.g. network mounts).

Implementation

FileSessionStore(
  String dirPath, {
  this.maxPersistedChainLength,
  this.snapshotPathPrefix,
  this.rejectBranchingSessions = false,
  Duration snapshotWatchPollInterval = _defaultSnapshotWatchPollInterval,
}) : _dir = Directory(dirPath).absolute,
     _snapshotWatchPollInterval = snapshotWatchPollInterval {
  _dir.createSync(recursive: true);
}