FrostMVC\FlashLog
use FrostMVC\FlashLog;
Generic key-value store with optional expiration, backed by either a Memcached handler or the filesystem (via PHP's system temp directory).
Used primarily by Session::$global for request-scoped flash data. Can also be instantiated directly for lightweight file-based caching.
| Property | Type | Description |
|---|---|---|
| FlashLog::$hashingAlgorithm | mixed |
|
| FlashLog::$baseDirectory | mixed |
Optional base directory for file-backed storage. When null (default), the system temp directory is used. Set this to an app-owned writable directory for persistence. |
| FlashLog::$namespace | mixed |
Unique identifier for the current site/web app. When null (default), it is auto-derived from the FrostMVC Site instance (namespace + URL) so multiple apps on the same host never share cache files. Override it when you need an explicit value. |
| ->__construct() | Creates a FlashLog instance bound to the given handler. |
| ->flash() | Reads and immediately removes the value for the given key (read-once). Useful for one-time status messages passed across redirects. |
| ->get() | Retrieves the value stored under the given key. Expired filesystem entries are removed and $defaultValue is returned. |
| ->getDirectory() | Returns the absolute path to a log file within the namespaced cache directory, or the directory itself when $filename is false. Creates the directory if it does not exist. |
| ->isSerialised() | Returns true if the given string appears to be a PHP-serialised value. Uses a conservative signature check before attempting unserialise, with object instantiation disabled for security. |
| ->remove() | Deletes the entry for the given key. |
| ->set() | Alias for write(). Sets a value for the given key. |
| ->setExpiration() | Sets an expiration time for the next write() call. Resets to 0 after write() is called. |
| ->write() | Stores a value under a per-app namespaced, hashed key. Keys are namespaced per app and hashed with SHA256 before storage. |
$flashLog->__construct($handler)
Creates a FlashLog instance bound to the given handler.
| $handler | Memcached|false |
A Memcached instance to use as the backend, or false to fall back to filesystem storage. |
$flashLog->flash($key, $defaultValue = false)
Reads and immediately removes the value for the given key (read-once). Useful for one-time status messages passed across redirects.
| $key | string |
Logical key. |
| $defaultValue | mixed |
Returned when the key is absent. Default:false |
mixed
$flashLog->get($key, $defaultValue = false)
Retrieves the value stored under the given key. Expired filesystem entries are removed and $defaultValue is returned.
| $key | string |
Logical key. |
| $defaultValue | mixed |
Returned when the key is absent or expired. Default:false |
mixed
$flashLog->getDirectory($filename = false)
Returns the absolute path to a log file within the namespaced cache directory, or the directory itself when $filename is false. Creates the directory if it does not exist.
| $filename | string|false |
Filename component (without extension), or false for the directory. Default:false |
string
$flashLog->isSerialised($string)
Returns true if the given string appears to be a PHP-serialised value. Uses a conservative signature check before attempting unserialise, with object instantiation disabled for security.
| $string | mixed |
The value to inspect. |
bool
$flashLog->remove($key)
Deletes the entry for the given key.
| $key | string |
Logical key. |
$flashLog->set($key, $value, $append = false)
Alias for write(). Sets a value for the given key.
| $key | string |
|
| $value | mixed |
|
| $append | bool |
When true, appends to any existing value (file backend only). Default:false |
$flashLog->setExpiration($seconds)
Sets an expiration time for the next write() call. Resets to 0 after write() is called.
| $seconds | int |
TTL in seconds. |
$this
$flashLog->write($key, $message, $append = false)
Stores a value under a per-app namespaced, hashed key. Keys are namespaced per app and hashed with SHA256 before storage.
Arrays and objects are stored as a serialised [expiry, value] envelope with an atomic LOCK_EX write, giving them TTL support. Scalars (strings, ints, etc.) are written raw with no TTL so log-style entries and their append mode keep working unchanged.
| $key | string |
Logical key. |
| $message | mixed |
The value to store. |
| $append | bool |
When true, appends to the existing file entry. Default:false |
Generated from core/classes/FlashLog.php (FrostMVC ).