DatabaseStore
class DatabaseStore implements PrunableStore, Store
Traits
Constants
| protected MAX_PRUNE_CHUNK_SIZE |
|
Methods
Calculate an admission decision and update accepted state values.
Calculate ordered group decisions against staged state.
Calculate a non-mutating policy inspection.
Calculate a cooldown extension and update its expiry.
Calculate a failure transition and update its state values.
Get the current epoch time in microseconds.
Create a new database rate limiter store.
Consume all policies in one transaction, leaving capacity unchanged on denial.
Calculate a locked group and persist its accepted state.
Atomically extend a cooldown block.
Inspect a policy without mutating its state.
Clear the state for a physical limiter key.
Prune expired state in bounded batches.
Mutate locked state, initializing a missing non-SQLite row in a new transaction.
Return an empty state row for a physical limiter key.
Insert an empty state row if the key does not exist.
Initialize and lock state for a missing non-SQLite physical limiter key.
Lock and read state, initializing SQLite state under its writer lock.
Find and lock numeric state for a physical limiter key.
Get and validate numeric state from a database row.
Write numeric state for a physical limiter key.
Ensure the connection can safely mutate limiter state.
Details
in
CalculatesRateLimits at line 27
protected LimitResult
calculateConsume(AdmissionPolicy $policy, int $now, int $value, int $secondaryValue, int $expiresAt)
Calculate an admission decision and update accepted state values.
in
CalculatesRateLimits at line 73
protected array
calculateMany(array $policies, int $now, array $states)
Calculate ordered group decisions against staged state.
in
CalculatesRateLimits at line 118
protected LimitResult|BackoffResult|CooldownResult
calculateInspection(AdmissionPolicy|Backoff|Cooldown $policy, int $now, int $value, int $secondaryValue, int $expiresAt)
Calculate a non-mutating policy inspection.
in
CalculatesRateLimits at line 172
protected CooldownResult
calculateCooldownBlock(int $durationMicroseconds, int $now, int $value, int $secondaryValue, int $expiresAt)
Calculate a cooldown extension and update its expiry.
in
CalculatesRateLimits at line 190
protected BackoffResult
calculateFailure(Backoff $backoff, int $now, int $value, int $secondaryValue, int $expiresAt)
Calculate a failure transition and update its state values.
in
CalculatesRateLimits at line 638
protected int
currentTimeInMicroseconds()
Get the current epoch time in microseconds.
at line 26
__construct(ConnectionResolverInterface $connections, string|null $connectionName, string $table)
Create a new database rate limiter store.
at line 36
LimitResult
consume(string $key, AdmissionPolicy $policy)
Atomically consume capacity from an admission policy.
at line 68
array
consumeMany(array $policies)
Consume all policies in one transaction, leaving capacity unchanged on denial.
at line 120
protected array
consumeStates(ConnectionInterface $connection, array $policies, array $states)
Calculate a locked group and persist its accepted state.
at line 136
CooldownResult
block(string $key, int $durationMicroseconds)
Atomically extend a cooldown block.
at line 165
LimitResult|BackoffResult|CooldownResult
inspect(string $key, AdmissionPolicy|Backoff|Cooldown $policy)
Inspect a policy without mutating its state.
at line 190
BackoffResult
recordFailure(string $key, Backoff $backoff)
Record a failure against a backoff policy.
at line 217
bool
clear(string $key)
Clear the state for a physical limiter key.
at line 231
int
pruneExpired(int $chunkSize = 1000)
Prune expired state in bounded batches.
at line 280
protected BackoffResult|CooldownResult|LimitResult
mutateState(ConnectionInterface $connection, string $key, Closure $callback)
Mutate locked state, initializing a missing non-SQLite row in a new transaction.
at line 308
protected array
emptyStateRow(string $key)
Return an empty state row for a physical limiter key.
at line 321
protected void
insertStateRow(ConnectionInterface $connection, string $key)
Insert an empty state row if the key does not exist.
at line 331
protected array
initializeStateRowForUpdate(ConnectionInterface $connection, string $key)
Initialize and lock state for a missing non-SQLite physical limiter key.
at line 355
protected array|null
stateForUpdate(ConnectionInterface $connection, string $key)
Lock and read state, initializing SQLite state under its writer lock.
at line 377
protected array|null
findStateForUpdate(ConnectionInterface $connection, string $key)
Find and lock numeric state for a physical limiter key.
at line 396
protected array
stateFromRow(object $row)
Get and validate numeric state from a database row.
at line 408
protected void
writeState(ConnectionInterface $connection, string $key, int $value, int $secondaryValue, int $expiresAt)
Write numeric state for a physical limiter key.
at line 427
protected void
ensureCanMutate(ConnectionInterface $connection)
Ensure the connection can safely mutate limiter state.