DatabaseRateLimiter
final class DatabaseRateLimiter implements RateLimiterInterface (View source)
Stores fixed-window buckets atomically in a MySQL or MariaDB table.
Constants
| private TABLE |
|
| private SCOPE_MAX_LENGTH |
|
Methods
Initializes database persistence and the application secret used for bucket HMACs.
Reads the current bucket state without creating or modifying a database row.
Atomically records an attempt and locks the resulting row until its decision is read.
Deletes the HMAC-addressed bucket for one opaque key.
Details
__construct
__construct(Database $database, string $secret)
Initializes database persistence and the application secret used for bucket HMACs.
status
RateLimitResult
status(string $key, string $scope, RateLimitPolicy $policy)
Reads the current bucket state without creating or modifying a database row.
Scope is validated but never persisted or otherwise applied by a status read.
hit
RateLimitResult
hit(string $key, string $scope, RateLimitPolicy $policy)
Atomically records an attempt and locks the resulting row until its decision is read.
Scope replaces prior bucket metadata for the same HMAC-addressed bucket.
clear
void
clear(string $key)
Deletes the HMAC-addressed bucket for one opaque key.