Dbi
Dbi
DBI-backed cache storage backend.
class Dbi extends \Hazaar\Cache\BackendExtends: Hazaar\Cache\Backend
Persists 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 = 5Type: int
config
Typed view of this backend's options.
private Dbi\Options $configType: Hazaar\Cache\Backend\Dbi\Options
db
DBI adapter instance used for cache table operations.
private Adapter $dbType: Hazaar\DBI\Adapter
Methods
available
Indicates whether this backend is available.
public available(): boolReturns: bool
init
Initializes DBI backend state and ensures table/schema availability.
public init(string $namespace): voidReturns: void
Parameters
| 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): boolReturns: bool
Parameters
| 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): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
set
Stores or updates a cache value.
public set(string $key, mixed $value, int $timeout): boolReturns: bool
Parameters
| 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): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
clear
Clears all entries from this backend namespace.
public clear(): boolReturns: bool
toArray
Returns all non-expired cache entries as an associative array.
public toArray(): arrayReturns: array
count
Returns the number of entries in the backend namespace.
public count(): intReturns: int
criteria
Generate the criteria for a key.
private criteria(string $key, bool $checkEmpty): arrayReturns: array
Parameters
| 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 Fri, 04 Sep 2026 23:32:16 +0000