TsgcWSRateLimiterMethods › LoadStateFromFile

LoadStateFromFile Method

Restores buckets and counters previously saved to a file.

Syntax

procedure LoadStateFromFile(const aFileName: string);

Parameters

NameTypeDescription
aFileNameconst stringSource file path, typically the same value used in a previous call to SaveStateToFile. The method returns silently if the file does not exist, so it is safe to call at startup before any state has ever been persisted.

Remarks

Opens the file as a TFileStream and delegates to LoadStateFromStream, which clears all current state and rehydrates Token Bucket sizes, Sliding Window timestamps, Fixed Window counters, burst tracker state and quota counters from the snapshot. Call once at startup (typically after assigning StorageFile) so counters continue from where they left off at the previous shutdown.

Example

// Rehydrate counters at startup
procedure TForm1.FormCreate(Sender: TObject);
begin
  sgcWSRateLimiter1.StorageFile := 'ratelimit.dat';
  sgcWSRateLimiter1.LoadStateFromFile(sgcWSRateLimiter1.StorageFile);
end;

Back to Methods