File
File
The file cache backend.
This backend will cache data to the filesystem. It is basically a "works all the time" backend that is available regardless of what modules are installed or server software is available. It is very handing for using caching on systems where no other cache backends are available.
Available config options:
- cache_dir - The directory to store cache files in. Default is to use a 'cache' directory in the application .runtime directory.
- file_prefix - This is an optional prefix to apply to the cache files. Useful if you want to separate your cache files. Default: no prefix
- use_zlib - Enable or disable zlib compression on the cache files. This can slow things down quite a bit more, but is useful when you are caching very large things. I wouldn't bother using it under normal circumstances. Default: false.
Properties
weight
protected int $weight = 4zlib
private bool $zlibcacheDir
private string $cacheDirtimeout
private int $timeoutlocal
private array $localstore
private BTree $store__openStore
private array $__openStoreshutdownRegistered
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
public available(): boolinit
public init(string $namespace): voidParameters
| Parameter | Type | Description |
|---|---|---|
$namespace | string |
has
Check if a value exists.
public has(string $key, bool $checkEmpty): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$checkEmpty | bool |
get
public get(string $key): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$key | string |
set
public set(string $key, mixed $value, ?int $timeout): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$value | mixed | |
$timeout | int |
remove
public remove(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string |
clear
public clear(): booltoArray
public toArray(): voidcount
public count(): intkeepalive
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 Sun, 01 Mar 2026 09:22:26 +0000