TsgcWSRateLimiter › Methods › SaveStateToStream
Persists the internal state to an arbitrary TStream.
procedure SaveStateToStream(aStream: TStream);
| Name | Type | Description |
|---|---|---|
aStream | TStream | Destination stream. Any TStream descendant is accepted — TFileStream for disk, TMemoryStream for in-memory snapshots, or a TStream wrapping a database BLOB / network socket for centralized state sharing. |
Writes a binary snapshot of all Token Bucket sizes, Sliding Window timestamps, Fixed Window counters, burst tracker state and quota counters to the given stream. Format is internal; the produced bytes must be fed back to LoadStateFromStream of a compatible component version. The caller owns the stream and is responsible for creating and freeing it. Use this overload (instead of SaveStateToFile) to persist state to a shared database or to replicate state between nodes.
var
oMemStream: TMemoryStream;
begin
oMemStream := TMemoryStream.Create;
try
sgcWSRateLimiter1.SaveStateToStream(oMemStream);
oMemStream.Position := 0;
UploadToSharedStorage(oMemStream);
finally
oMemStream.Free;
end;
end;