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
Methods
__construct
Cache rate limiter constructor.
public __construct(array|Options $options): voidWithout a type, this uses the app's cache.backend config, falling back to shm and then file. The session backend is never used, because a per-session limit is easily dodged by dropping the cookie.
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | array | Hazaar\Util\RateLimiter\Backend\Cache\Options |
get
public get(string $identifier): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string |
set
public set(string $identifier, array $log): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | |
$log | array |
remove
public remove(string $identifier): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string |
getKey
Get the key for rate limiting based on the provided identifier.
private getKey(string $identifier): stringReturns: string
The key is hashed, because some cache backends (e.g. file) limit keys to 32 bytes, and an identifier such as a bucket name plus an IPv6 address is longer than that.
Parameters
| Parameter | Type | Description |
|---|---|---|
$identifier | string | the identifier used for rate limiting |
Generated by Hazaar API Doc Generator on Thu, 22 Oct 2026 05:05:29 +0000