Cache
Cache
Rate limiter backend using cache storage.
class Cache extends \Hazaar\Util\RateLimiter\BackendExtends: Hazaar\Util\RateLimiter\Backend
This 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 $cacheType: Hazaar\Cache\Adapter
prefix
The prefix used for rate limiter cache keys.
private string $prefix = 'rate_limiter_'Type: string
index
private array $indexType: array
Methods
__construct
Cache rate limiter constructor.
public __construct(array|Options $options): voidParameters
| Parameter | Type | Description |
|---|---|---|
$options | array | Hazaar\Util\RateLimiter\Backend\Cache\Options |
shutdown
Persists all rate limiter data in the local index to the cache.
public shutdown(): voidReturns: void
This 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): arrayReturns: array
Retrieves 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): arrayReturns: array
This 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): voidReturns: void
Parameters
| 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): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | the identifier used for rate limiting |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000