Dbi
Dbi
DBI-backed cache storage backend.
class Dbi extends \Hazaar\Cache\Backend\BackendPersists cache entries in a database table using Hazaar DBI, with support for per-entry expiry timestamps and namespace-based table isolation.
Backend initialization ensures the target schema/table exists and creates the required structure when missing. Lookup criteria automatically filter expired records.
Properties
weight
Backend priority weight used in backend-chain ordering.
protected int $weight = 5db
DBI adapter instance used for cache table operations.
private Adapter $dbMethods
available
Indicates whether this backend is available.
public available(): boolinit
Initializes DBI backend state and ensures table/schema availability.
public init(string $namespace): voidParameters
| Parameter | Type | Description |
|---|---|---|
$namespace | string | cache namespace (used as table name) |
has
Checks whether a non-expired cache entry exists for a key.
public has(string $key, bool $checkEmpty): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
$checkEmpty | bool | whether to exclude empty/null values |
get
Retrieves a non-expired cache value for a key.
public get(string $key): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
set
Stores or updates a cache value.
public set(string $key, mixed $value, int $timeout): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
$value | mixed | value to persist |
$timeout | int | TTL in seconds (0 means no explicit expiry) |
remove
Removes a key from storage.
public remove(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
clear
Clears all entries from this backend namespace.
public clear(): booltoArray
Returns all non-expired cache entries as an associative array.
public toArray(): voidcount
Returns the number of entries in the backend namespace.
public count(): intcriteria
Generate the criteria for a key.
private criteria(string $key, bool $checkEmpty): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | The key to generate criteria for |
$checkEmpty | bool | Check if the value is empty |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:25 +0000