File
File
Filesystem/B-Tree cache backend.
class File extends \Hazaar\Cache\BackendExtends: Hazaar\Cache\Backend
Persists 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 = 4Type: int
config
Typed view of this backend's options.
private File\Options $configType: Hazaar\Cache\Backend\File\Options
zlib
Indicates whether zlib support is available in the current runtime.
private bool $zlibType: bool
cacheDir
Absolute directory path used for backend cache files.
private string $cacheDirType: string
timeout
Current namespace timeout epoch for keepalive/expiry handling.
private int $timeoutType: int
local
private array $localType: array
store
Open B-Tree store instance for the active namespace.
private BTree $storeType: Hazaar\Util\BTree
__openStore
private array $__openStoreType: array
shutdownRegistered
Tracks whether global shutdown cleanup has been registered.
private bool $shutdownRegisteredType: bool
Methods
close
Closes the cache backend, storing the timeout value if set, and registers a shutdown function
public close(): boolReturns: bool
to 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(): boolReturns: bool
init
Initializes storage paths, opens the namespace B-Tree store, and configures capabilities.
public init(string $namespace): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$namespace | string | active cache namespace |
has
Check if a value exists.
public has(string $key, bool $checkEmpty): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$checkEmpty | bool |
get
Retrieves a cache value.
public get(string $key): mixedReturns: mixed
Parameters
| 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): boolReturns: bool
Parameters
| 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): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
clear
Clears all keys in the active namespace.
public clear(): boolReturns: bool
toArray
public toArray(): arrayReturns: array
count
Returns the number of active (non-expired) keys in this namespace.
public count(): intReturns: int
keepalive
Extends namespace timeout when namespace TTL is enabled.
private keepalive(): voidReturns: void
load
Load the key value from storage.
private load(string $key, ?array $cache): mixedReturns: mixed
This 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 Fri, 04 Sep 2026 23:32:16 +0000