Chain
Chain
Multi-backend chained cache backend.
class Chain extends \Hazaar\Cache\Backend\BackendComposes multiple cache backends to provide fallback behavior and redundancy. Backend instances are ordered by weight, allowing reads to prefer faster backends and repopulate slower/missed layers when a hit is found downstream.
Configuration expects a backends map where keys are backend names and values are backend-specific option arrays.
Properties
backends
private array $backendsorder
private array $orderMethods
available
Indicates that the chain backend is always available.
public available(): boolinit
Initializes and orders configured backend chain members.
public init(string $namespace): voidParameters
| Parameter | Type | Description |
|---|---|---|
$namespace | string | namespace passed to each backend instance |
close
Closes all cache backend connections in the chain.
public close(): boolIterates through each backend and calls its close() method.
has
Checks whether any backend in the chain contains the key.
public has(string $key, bool $checkEmpty): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
$checkEmpty | bool | whether to treat empty values as missing |
get
Retrieves a value from the backend chain by weighted order.
public get(string $key): mixedOn hit from a lower-priority backend, missed higher-priority backends are repopulated with the discovered value.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
set
Stores a value in all configured backends.
public set(string $key, mixed $value, int $timeout): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
$value | mixed | value to store |
$timeout | int | TTL in seconds |
remove
Removes a key from all configured backends.
public remove(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
clear
Clears all configured backends.
public clear(): boolsetExpireTimeout
Updates expire timeout option across all configured backends.
public setExpireTimeout(int $timeout): voidParameters
| Parameter | Type | Description |
|---|---|---|
$timeout | int | expire timeout in seconds |
toArray
Returns all cached values from the first backend in the chain.
public toArray(): voidcount
Returns key count from the first backend in the chain.
public count(): intGenerated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:25 +0000