Welcome to FrostSW!

FrostMVC PHP Framework

Documentation   |   Version

FlashLog

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.

Properties

PropertyTypeDescription
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.

Methods

->__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.

__construct()

$flashLog->__construct($handler)

Creates a FlashLog instance bound to the given handler.

Parameters

$handler Memcached|false

A Memcached instance to use as the backend, or false to fall back to filesystem storage.

flash()

$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.

Parameters

$key string

Logical key.

$defaultValue mixed

Returned when the key is absent.

Default: false

Returns

mixed

get()

$flashLog->get($key, $defaultValue = false)

Retrieves the value stored under the given key. Expired filesystem entries are removed and $defaultValue is returned.

Parameters

$key string

Logical key.

$defaultValue mixed

Returned when the key is absent or expired.

Default: false

Returns

mixed

getDirectory()

$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.

Parameters

$filename string|false

Filename component (without extension), or false for the directory.

Default: false

Returns

string

isSerialised()

$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.

Parameters

$string mixed

The value to inspect.

Returns

bool

remove()

$flashLog->remove($key)

Deletes the entry for the given key.

Parameters

$key string

Logical key.

set()

$flashLog->set($key, $value, $append = false)

Alias for write(). Sets a value for the given key.

Parameters

$key string
$value mixed
$append bool

When true, appends to any existing value (file backend only).

Default: false

setExpiration()

$flashLog->setExpiration($seconds)

Sets an expiration time for the next write() call. Resets to 0 after write() is called.

Parameters

$seconds int

TTL in seconds.

Returns

$this

write()

$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.

Parameters

$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 ).