Chain
Chain
Multi-backend chained cache backend.
class Chain extends \Hazaar\Cache\BackendExtends: Hazaar\Cache\Backend
Composes 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 $backendsType: array
order
private array $orderType: array
Methods
available
Indicates that the chain backend is always available.
public available(): boolReturns: bool
init
Initializes and orders configured backend chain members.
public init(string $namespace): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$namespace | string | namespace passed to each backend instance |
close
Closes all cache backend connections in the chain.
public close(): boolReturns: bool
Iterates 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): boolReturns: bool
Parameters
| 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): mixedReturns: mixed
On 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): boolReturns: bool
Parameters
| 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): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
clear
Clears all configured backends.
public clear(): boolReturns: bool
setExpireTimeout
Updates expire timeout option across all configured backends.
public setExpireTimeout(int $timeout): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$timeout | int | expire timeout in seconds |
toArray
Returns all cached values from the first backend in the chain.
public toArray(): arrayReturns: array
count
Returns key count from the first backend in the chain.
public count(): intReturns: int
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000