Cache
Cache
Rate limiter backend using cache storage.
class Cache extends \Hazaar\Util\RateLimiter\Backend\BackendThis backend implementation uses a cache adapter to store and manage rate limiting data. It supports configurable cache options and prefixing for rate limiter keys.
Properties
cache
The cache adapter instance used for storing rate limiter data.
private Adapter $cacheprefix
The prefix used for rate limiter cache keys.
private string $prefix = 'rate_limiter_'index
private array $indexMethods
__construct
Cache rate limiter constructor.
public __construct(array $options): voidParameters
| Parameter | Type | Description |
|---|---|---|
$options | array | the options for the cache |
shutdown
Persists all rate limiter data in the local index to the cache.
public shutdown(): voidThis method should be called during shutdown to ensure all in-memory rate limiter information is saved to the cache backend.
check
Checks and updates the rate limit information for a given identifier.
public check(string $identifier): voidRetrieves the current rate limit info for the specified identifier, appends the current timestamp to the log, updates the internal index, and returns the updated info array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | the unique identifier to check and update rate limit info for |
get
Retrieves and returns the rate limiting information for a given identifier.
public get(string $identifier): voidThis method fetches the rate limiting log from the cache using the provided identifier. It removes any log entries that are outside the configured time window. If no log exists, it initializes an empty log array. The resulting information is stored in the local index and returned.
Parameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | the unique identifier for which to retrieve rate limiting data |
remove
Removes the rate limit information for the specified identifier.
public remove(string $identifier): voidParameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | the identifier for which to remove the rate limit information |
getKey
Get the key for rate limiting based on the provided identifier.
private getKey(string $identifier): stringParameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | the identifier used for rate limiting |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000