File
File
Filesystem/B-Tree cache backend.
class File extends \Hazaar\Cache\Backend\BackendPersists cache entries to a namespaced on-disk B-Tree store, making it a broadly available fallback backend when in-memory extensions are unavailable.
Features include:
- Optional zlib compression for stored payloads
- Per-value expiration support
- Optional namespace TTL with keepalive extension on access
- Deferred shutdown cleanup of expired namespace files
Properties
weight
Backend priority weight used in chained backend ordering.
protected int $weight = 4zlib
Indicates whether zlib support is available in the current runtime.
private bool $zlibcacheDir
Absolute directory path used for backend cache files.
private string $cacheDirtimeout
Current namespace timeout epoch for keepalive/expiry handling.
private int $timeoutlocal
private array $localstore
Open B-Tree store instance for the active namespace.
private BTree $store__openStore
private array $__openStoreshutdownRegistered
Tracks whether global shutdown cleanup has been registered.
private bool $shutdownRegisteredMethods
close
Closes the cache backend, storing the timeout value if set, and registers a shutdown function
public close(): boolto clean up expired cache files in the cache directory.
The shutdown function iterates through the cache directory, checks each file's modification time, and removes files whose namespace timeout has expired plus an additional 5 minutes.
available
Indicates whether this backend is available.
public available(): boolinit
Initializes storage paths, opens the namespace B-Tree store, and configures capabilities.
public init(string $namespace): voidParameters
| Parameter | Type | Description |
|---|---|---|
$namespace | string | active cache namespace |
has
Check if a value exists.
public has(string $key, bool $checkEmpty): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$checkEmpty | bool |
get
Retrieves a cache value.
public get(string $key): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
set
Stores a value in the B-Tree cache backend.
public set(string $key, mixed $value, ?int $timeout): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
$value | mixed | value to store |
$timeout | int | optional per-value timeout in seconds |
remove
Removes a key from cache.
public remove(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
clear
Clears all keys in the active namespace.
public clear(): booltoArray
public toArray(): voidcount
Returns the number of active (non-expired) keys in this namespace.
public count(): intkeepalive
Extends namespace timeout when namespace TTL is enabled.
private keepalive(): voidload
Load the key value from storage.
private load(string $key, ?array $cache): mixedThis should only happen once and then it will be stored in memory and only written again when changed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$cache | array |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:25 +0000