class SwooleStore implements Store

Traits

Methods

calculateConsume(AdmissionPolicy $policy, int $now, int $value, int $secondaryValue, int $expiresAt)

Calculate an admission decision and update accepted state values.

array
calculateMany(array $policies, int $now, array $states)

Calculate ordered group decisions against staged state.

calculateInspection(AdmissionPolicy|Backoff|Cooldown $policy, int $now, int $value, int $secondaryValue, int $expiresAt)

Calculate a non-mutating policy inspection.

calculateCooldownBlock(int $durationMicroseconds, int $now, int $value, int $secondaryValue, int $expiresAt)

Calculate a cooldown extension and update its expiry.

calculateFailure(Backoff $backoff, int $now, int $value, int $secondaryValue, int $expiresAt)

Calculate a failure transition and update its state values.

int
currentTimeInMicroseconds()

Get the current epoch time in microseconds.

__construct(TableState $state, float $memoryLimitBuffer, LoggerInterface $logger)

Create a new Swoole rate limiter store.

consume(string $key, AdmissionPolicy $policy)

Atomically consume capacity from an admission policy.

array
consumeMany(array $policies)

Consume all policies while holding their shared table locks.

block(string $key, int $durationMicroseconds)

Atomically extend a cooldown block.

inspect(string $key, AdmissionPolicy|Backoff|Cooldown $policy)

Inspect a policy without mutating its state.

recordFailure(string $key, Backoff $backoff)

Record a failure against a backoff policy.

bool
clear(string $key)

Clear the state for a physical limiter key.

int
pruneExpiredRows()

Prune every expired entry.

int
maintain()

Prune expired entries and report table pressure.

array
storedState(string $key)

Get and validate numeric state for a physical limiter key.

bool
writeState(string $key, int $value, int $secondaryValue, int $expiresAt)

Write numeric state for a physical limiter key.

void
reportTablePressure()

Report exhausted table headroom after periodic pruning.

Details

protected LimitResult calculateConsume(AdmissionPolicy $policy, int $now, int $value, int $secondaryValue, int $expiresAt)

Calculate an admission decision and update accepted state values.

Parameters

AdmissionPolicy $policy
int $now
int $value
int $secondaryValue
int $expiresAt

Return Value

LimitResult

protected array calculateMany(array $policies, int $now, array $states)

Calculate ordered group decisions against staged state.

Parameters

array $policies
int $now
array $states

Return Value

array

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.

Parameters

AdmissionPolicy|Backoff|Cooldown $policy
int $now
int $value
int $secondaryValue
int $expiresAt

Return Value

LimitResult|BackoffResult|CooldownResult

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.

Parameters

int $durationMicroseconds
int $now
int $value
int $secondaryValue
int $expiresAt

Return Value

CooldownResult

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.

Parameters

Backoff $backoff
int $now
int $value
int $secondaryValue
int $expiresAt

Return Value

BackoffResult

in CalculatesRateLimits at line 638
protected int currentTimeInMicroseconds()

Get the current epoch time in microseconds.

Return Value

int

at line 22
__construct(TableState $state, float $memoryLimitBuffer, LoggerInterface $logger)

Create a new Swoole rate limiter store.

Parameters

TableState $state
float $memoryLimitBuffer
LoggerInterface $logger

at line 37
LimitResult consume(string $key, AdmissionPolicy $policy)

Atomically consume capacity from an admission policy.

Parameters

string $key
AdmissionPolicy $policy

Return Value

LimitResult

at line 84
array consumeMany(array $policies)

Consume all policies while holding their shared table locks.

Parameters

array $policies

Return Value

array

at line 148
CooldownResult block(string $key, int $durationMicroseconds)

Atomically extend a cooldown block.

Parameters

string $key
int $durationMicroseconds

Return Value

CooldownResult

at line 190
LimitResult|BackoffResult|CooldownResult inspect(string $key, AdmissionPolicy|Backoff|Cooldown $policy)

Inspect a policy without mutating its state.

Parameters

string $key
AdmissionPolicy|Backoff|Cooldown $policy

Return Value

LimitResult|BackoffResult|CooldownResult

at line 210
BackoffResult recordFailure(string $key, Backoff $backoff)

Record a failure against a backoff policy.

Parameters

string $key
Backoff $backoff

Return Value

BackoffResult

at line 250
bool clear(string $key)

Clear the state for a physical limiter key.

Parameters

string $key

Return Value

bool

at line 261
int pruneExpiredRows()

Prune every expired entry.

Return Value

int

at line 297
int maintain()

Prune expired entries and report table pressure.

Return Value

int

at line 310
protected array storedState(string $key)

Get and validate numeric state for a physical limiter key.

Parameters

string $key

Return Value

array

at line 336
protected bool writeState(string $key, int $value, int $secondaryValue, int $expiresAt)

Write numeric state for a physical limiter key.

Parameters

string $key
int $value
int $secondaryValue
int $expiresAt

Return Value

bool

at line 348
protected void reportTablePressure()

Report exhausted table headroom after periodic pruning.

Return Value

void