TsgcWSRateLimiterMethods › LoadStateFromStream

LoadStateFromStream Method

Restores the internal state from an arbitrary TStream.

Syntax

procedure LoadStateFromStream(aStream: TStream);

Parameters

NameTypeDescription
aStreamTStreamSource stream positioned at the first byte produced by a previous SaveStateToStream call. Any TStream descendant is accepted.

Remarks

Clears all current state and rehydrates Token Bucket sizes, Sliding Window timestamps, Fixed Window counters, burst tracker state and quota counters from the stream. Use this overload (instead of LoadStateFromFile) when the saved state lives in a database BLOB, in shared storage or in memory. The caller owns the stream and is responsible for positioning it before the call and freeing it afterwards.

Example

var
  oMemStream: TMemoryStream;
begin
  oMemStream := DownloadFromSharedStorage;
  try
    oMemStream.Position := 0;
    sgcWSRateLimiter1.LoadStateFromStream(oMemStream);
  finally
    oMemStream.Free;
  end;
end;

Back to Methods