Backend
Backend
Abstract base class for cache backend implementations.
class Backend implements \Hazaar\Cache\Interface\BackendImplements: Hazaar\Cache\Interface\Backend
Provides shared option/state handling and capability registration used by concrete cache backends (file, shm, sqlite, etc.). The frontend cache adapter queries backend capabilities via Hazaar\Cache\Backend::can to determine behavior such as object serialization strategy and array export support.
Subclasses are responsible for implementing storage operations defined by Hazaar\Cache\Interface\Backend, while this class supplies common defaults for optional behaviors like locking and connection closing.
Properties
options
The backend options.
public array $optionsType: array
weight
Backend preference/priority weight used when selecting among candidates.
protected int $weight = 10Type: int
namespace
public string $namespaceType: string
capabilities
The backends list of capabilities.
private array $capabilitiesType: array
Standard 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(): boolReturns: bool
Default implementation is a no-op.
can
Checks whether a backend capability is supported.
public can(string $key): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | capability name |
getWeight
Returns backend selection weight.
public getWeight(): intReturns: int
setOption
Sets or overrides a backend option.
public setOption(string $key, mixed $value): voidReturns: void
Parameters
| 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): boolReturns: bool
Default 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): boolReturns: bool
Default implementation indicates unsupported locking.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | lock key |
addCapabilities
Registers one or more backend capabilities.
protected addCapabilities(string $args): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$args | string |
configure
protected configure(array $options): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | array |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000