Documentation

CFileCache
in package
implements ICache

Implements the ICache interface using the local filesystem.

Stores cache data as serialized and optionally encrypted files. It is recommended to use a RAM-based filesystem like /dev/shm for performance.

Table of Contents

Interfaces

ICache
Interface for caching data and pages.

Properties

$area_name  : string
$cache_path  : string
$encryption_cipher  : string
$encryption_enabled  : bool
$encryption_key  : string
$uid  : int

Methods

__construct()  : mixed
Constructor for CFileCache.
Clear()  : void
Clears the cache. Can be filtered by a search string.
ClearArea()  : void
Removes all items from a specific area.
Delete()  : void
Deletes a specific item from the cache.
Exists()  : bool
Checks if an item exists in the cache for the current user.
ExistsGlobal()  : bool
Checks if a global item (valid for all users) exists in the cache.
Get()  : mixed
Retrieves the value of a cached item.
GetCacheNames()  : array<string|int, string>|false
Provides a list of all cache keys within the current scope.
GetCachePath()  : string
Returns the physical path where cache files are stored.
GetGlobal()  : mixed
Retrieves the value of a global cached item (valid for all users).
GetName()  : string
Generates the actual internal key for a given name.
Set()  : void
Stores an item in the cache for the current user.
SetArea()  : void
Sets the name of the current area.
SetGlobal()  : void
Stores a global item in the cache (valid for all users).
SetUid()  : void
Sets the user ID for the current context.
WriteDebug()  : void
Writes a message to a cache-specific log file for debugging purposes.
CreatePathIfNotExists()  : void
Creates a directory path if it does not already exist.
DecryptData()  : string|null
Decrypts data using OpenSSL.
EncryptData()  : string|null
Encrypts data using OpenSSL.

Properties

$area_name

private string $area_name = 'default'

The current cache area name for grouping related items

$cache_path

private string $cache_path

The base path where cache files are stored

$encryption_cipher

private string $encryption_cipher

The OpenSSL cipher algorithm to use

$encryption_enabled

private bool $encryption_enabled

Whether data encryption is enabled

$encryption_key

private string $encryption_key

The encryption key for data encryption

$uid

private int $uid = 0

The current user ID (0 for global cache)

Methods

__construct()

Constructor for CFileCache.

public __construct([string|null $domain_name = null ][, string|null $app_name = null ]) : mixed
Parameters
$domain_name : string|null = null

The domain name to isolate cache. Defaults to DOMAIN_NAME constant.

$app_name : string|null = null

The application name to isolate cache. Defaults to APP_NAME constant.

Clear()

Clears the cache. Can be filtered by a search string.

public Clear([string $needle = '*' ]) : void
Parameters
$needle : string = '*'

Removes all keys containing this string. If '*' or empty, clears the entire current scope (area/user).

ClearArea()

Removes all items from a specific area.

public ClearArea(string $area_name) : void
Parameters
$area_name : string

The name of the area to clear.

Delete()

Deletes a specific item from the cache.

public Delete(string $name) : void
Parameters
$name : string

The key of the item to delete.

Exists()

Checks if an item exists in the cache for the current user.

public Exists(string $name[, string|null $area_name = null ]) : bool
Parameters
$name : string

The key of the item to check.

$area_name : string|null = null

The area name. If null, the current area is used.

Return values
bool —

True if the item exists, false otherwise.

ExistsGlobal()

Checks if a global item (valid for all users) exists in the cache.

public ExistsGlobal(string $name[, string|null $area_name = null ]) : bool
Parameters
$name : string

The key of the item to check.

$area_name : string|null = null

The area name. If null, the current area is used.

Return values
bool —

True if the item exists, false otherwise.

Get()

Retrieves the value of a cached item.

public Get(string $name[, string|null $area_name = null ]) : mixed
Parameters
$name : string

The key of the item to retrieve.

$area_name : string|null = null

The area name. If null, the current area is used.

Return values
mixed —

The cached item's value (can be a scalar, array, or object), or null if not found or on error.

GetCacheNames()

Provides a list of all cache keys within the current scope.

public GetCacheNames() : array<string|int, string>|false
Return values
array<string|int, string>|false —

An array with a list of cache keys, or false if the scope is empty or not accessible.

GetCachePath()

Returns the physical path where cache files are stored.

public GetCachePath() : string
Return values
string —

The cache path of the application. Returns an empty string if not applicable.

GetGlobal()

Retrieves the value of a global cached item (valid for all users).

public GetGlobal(string $name[, string|null $area_name = null ]) : mixed
Parameters
$name : string

The key of the item to retrieve.

$area_name : string|null = null

The area name. If null, the current area is used.

Return values
mixed —

The cached item's value, or null if not found or on error.

GetName()

Generates the actual internal key for a given name.

public GetName(string $name) : string
Parameters
$name : string

The public key of the item.

Return values
string —

The complete internal key used by the cache system.

Set()

Stores an item in the cache for the current user.

public Set(string $name, mixed $value[, string|null $area_name = null ]) : void
Parameters
$name : string

The key of the item to store.

$value : mixed

The value to be stored.

$area_name : string|null = null

The area name. If null, the current area is used.

SetArea()

Sets the name of the current area.

public SetArea(string $area_name) : void
Parameters
$area_name : string

The name of the area.

SetGlobal()

Stores a global item in the cache (valid for all users).

public SetGlobal(string $name, mixed $value[, string|null $area_name = null ]) : void
Parameters
$name : string

The key of the item to store.

$value : mixed

The value to be stored.

$area_name : string|null = null

The area name. If null, the current area is used.

SetUid()

Sets the user ID for the current context.

public SetUid(int $uid) : void
Parameters
$uid : int

The ID of the current user. A value of 0 typically represents a global (non-user-specific) context.

WriteDebug()

Writes a message to a cache-specific log file for debugging purposes.

public WriteDebug(mixed $msg) : void
Parameters
$msg : mixed

The string message or object to write to the log file.

CreatePathIfNotExists()

Creates a directory path if it does not already exist.

private CreatePathIfNotExists(string $path) : void
Parameters
$path : string

The full directory path to create.

DecryptData()

Decrypts data using OpenSSL.

private DecryptData(string $data) : string|null
Parameters
$data : string

The base64-encoded string to decrypt.

Return values
string|null —

The decrypted plaintext data, or null on failure.

EncryptData()

Encrypts data using OpenSSL.

private EncryptData(string $data) : string|null
Parameters
$data : string

The plaintext data to encrypt.

Return values
string|null —

The base64-encoded encrypted data (IV prepended), or null on failure.


        
On this page

Search results