Shared Variables Overview

Maintain lightweight in-memory state across requests and routes. This section covers how to declare and safely use variables defined prior to configuration inside PowerShell route script blocks.


Chapter

Order Chapter Focus
1 Using Shared Variables Share thread-safe objects (counters, caches) across routes
2 Shared State Register, query, and update explicit shared-state entries
3 Shared State Snapshots Export, reset, and restore shared in-memory state

Quick Start

Run the sample:

pwsh .\docs\pwsh\tutorial\examples\4.1-Shared-Variables.ps1

Then:

curl http://127.0.0.1:5000/visit
curl http://127.0.0.1:5000/show

For explicit shared-state cmdlets, run:

pwsh .\docs\pwsh\tutorial\examples\4.2-Shared-State.ps1

For snapshot export/import, run:

pwsh .\docs\pwsh\tutorial\examples\4.3-Shared-State-Snapshots.ps1

Next

Proceed to: Using Shared VariablesShared StateShared State SnapshotsLogging


Contributions & ideas welcome — open an issue or PR.


Table of contents