TsgcWSRateLimiter › Methods › LoadStateFromFile
Restores buckets and counters previously saved to a file.
procedure LoadStateFromFile(const aFileName: string);
| Name | Type | Description |
|---|---|---|
aFileName | const string | Source 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. |
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.
// Rehydrate counters at startup
procedure TForm1.FormCreate(Sender: TObject);
begin
sgcWSRateLimiter1.StorageFile := 'ratelimit.dat';
sgcWSRateLimiter1.LoadStateFromFile(sgcWSRateLimiter1.StorageFile);
end;