Backend
Backend
Abstract base class for cache backend implementations.
class Backend implements \Hazaar\Cache\BackendInterfaceProvides shared option/state handling and capability registration used by concrete cache backends (file, shm, sqlite, etc.). The frontend cache adapter queries backend capabilities via {@see self::can()} to determine behavior such as object serialization strategy and array export support.
Subclasses are responsible for implementing storage operations defined by {@see BackendInterface}, while this class supplies common defaults for optional behaviors like locking and connection closing.
Properties
options
The backend options.
public array $optionsweight
Backend preference/priority weight used when selecting among candidates.
protected int $weight = 10namespace
public string $namespacecapabilities
The backends list of capabilities.
private array $capabilitiesStandard capabilities are:
- store_objects - Backend can directly store & return objects. Whether the backend itself really can (like APCu) or the backend class takes care of this.
- compress - Can compress objects being stored. If the backend can do this, then we don't want the frontend to ever do it.
- array - Can return all elements in the cache as an associative array
- expire_ns - Backend supports storage TTLs on the namespace as a whole.
- expire_val - Backend supports storage TTLs on individual values stored within the namespace
- keepalive - When a value is accessed it's TTL can be reset to keep it alive in cache.
Methods
__construct
public __construct(array $options, string $namespace): voidParameters
| Parameter | Type | Description |
|---|---|---|
$options | array | |
$namespace | string |
close
Closes backend resources, if applicable.
public close(): boolDefault implementation is a no-op.
can
Checks whether a backend capability is supported.
public can(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | capability name |
getWeight
Returns backend selection weight.
public getWeight(): intsetOption
Sets or overrides a backend option.
public setOption(string $key, mixed $value): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | option key |
$value | mixed | option value |
lock
Attempts to acquire a lock for a cache key.
public lock(string $key): boolDefault implementation indicates unsupported locking.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | lock key |
unlock
Attempts to release a lock for a cache key.
public unlock(string $key): boolDefault implementation indicates unsupported locking.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | lock key |
addCapabilities
Registers one or more backend capabilities.
protected addCapabilities(string $args): voidParameters
| Parameter | Type | Description |
|---|---|---|
$args | string |
configure
protected configure(array $options): voidParameters
| Parameter | Type | Description |
|---|---|---|
$options | array |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:25 +0000