TsgcWSRateLimiterMethods › SaveStateToStream

SaveStateToStream Method

Persists the internal state to an arbitrary TStream.

Syntax

procedure SaveStateToStream(aStream: TStream);

Parameters

NameTypeDescription
aStreamTStreamDestination 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.

Remarks

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.

Example

var
  oMemStream: TMemoryStream;
begin
  oMemStream := TMemoryStream.Create;
  try
    sgcWSRateLimiter1.SaveStateToStream(oMemStream);
    oMemStream.Position := 0;
    UploadToSharedStorage(oMemStream);
  finally
    oMemStream.Free;
  end;
end;

Back to Methods