TsgcWSRateLimiterMethods › SaveStateToFile

SaveStateToFile Method

Persists all buckets and counters to the given file.

Syntax

procedure SaveStateToFile(const aFileName: string);

Parameters

NameTypeDescription
aFileNameconst stringDestination file path. The file is overwritten if it exists. Usually the same value as the StorageFile property.

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 file by creating a TFileStream and delegating to SaveStateToStream. Call this at graceful shutdown (and optionally from a periodic timer) so that counters survive a process restart — a rolling Token Bucket continues refilling from where it stopped instead of starting fresh and accepting a huge burst.

Example

// Persist on shutdown so counters survive restarts
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  sgcWSRateLimiter1.SaveStateToFile('ratelimit.dat');
end;

Back to Methods