class RateLimiter

Properties

protected Repository $cache

The cache store implementation.

Methods

void
__construct(Repository $cache)

Create a new rate limiter instance.

bool
tooManyAttempts(string $key, int $maxAttempts, float|int $decayMinutes = 1)

Determine if the given key has been "accessed" too many times.

void
lockout(string $key, int $decayMinutes)

Add the lockout key to the cache.

int
hit(string $key, float|int $decayMinutes = 1)

Increment the counter for a given key for a given decay time.

mixed
attempts(string $key)

Get the number of attempts for the given key.

mixed
resetAttempts(string $key)

Reset the number of attempts for the given key.

int
retriesLeft(string $key, int $maxAttempts)

Get the number of retries left for the given key.

void
clear(string $key)

Clear the hits and lockout for the given key.

int
availableIn(string $key)

Get the number of seconds until the "key" is accessible again.

Details

at line 23
void __construct(Repository $cache)

Create a new rate limiter instance.

Parameters

Repository $cache

Return Value

void

at line 36
bool tooManyAttempts(string $key, int $maxAttempts, float|int $decayMinutes = 1)

Determine if the given key has been "accessed" too many times.

Parameters

string $key
int $maxAttempts
float|int $decayMinutes

Return Value

bool

at line 60
protected void lockout(string $key, int $decayMinutes)

Add the lockout key to the cache.

Parameters

string $key
int $decayMinutes

Return Value

void

at line 74
int hit(string $key, float|int $decayMinutes = 1)

Increment the counter for a given key for a given decay time.

Parameters

string $key
float|int $decayMinutes

Return Value

int

at line 93
mixed attempts(string $key)

Get the number of attempts for the given key.

Parameters

string $key

Return Value

mixed

at line 104
mixed resetAttempts(string $key)

Reset the number of attempts for the given key.

Parameters

string $key

Return Value

mixed

at line 116
int retriesLeft(string $key, int $maxAttempts)

Get the number of retries left for the given key.

Parameters

string $key
int $maxAttempts

Return Value

int

at line 129
void clear(string $key)

Clear the hits and lockout for the given key.

Parameters

string $key

Return Value

void

at line 142
int availableIn(string $key)

Get the number of seconds until the "key" is accessible again.

Parameters

string $key

Return Value

int