TsgcWSRateLimiter › Methods › SaveStateToFile
Persists all buckets and counters to the given file.
procedure SaveStateToFile(const aFileName: string);
| Name | Type | Description |
|---|---|---|
aFileName | const string | Destination file path. The file is overwritten if it exists. Usually the same value as the StorageFile property. |
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.
// Persist on shutdown so counters survive restarts
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
sgcWSRateLimiter1.SaveStateToFile('ratelimit.dat');
end;