Session
Session
PHP session-backed cache backend.
class Session extends \Hazaar\Cache\Backend\BackendStores cache values inside $_SESSION under application-base and namespace keys to avoid collisions across applications and cache contexts.
Responsibilities:
- Starts/configures session state when needed
- Maintains namespace-level timeout and access timestamps
- Supports per-value expirations for cached entries
- Exposes standard cache operations over session storage
Properties
weight
Backend priority weight used in chain backend ordering.
protected int $weight = 3timeout
Namespace/session inactivity timeout in seconds.
private int $timeout = 3600values
private array $valuesstarted
Tracks whether this process has started the PHP session.
private bool $startedbaseName
Application base path used for top-level session namespacing.
private string $baseName = '/'Methods
available
Indicates whether this backend is available.
public available(): boolinit
public init(string $namespace): voidThe session backend init method is responsible for maintaining a valid session. If a session has not already been started it will configure and start one automatically. You can specify a namespace for the session. The constructor will also maintain any timeouts for values as per the application configuration.
Parameters
| Parameter | Type | Description |
|---|---|---|
$namespace | string | The namespace to use for this session |
close
Writes and closes the active PHP session.
public close(): boolhas
Checks whether a cache key exists and is not expired.
public has(string $key, bool $checkEmpty): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
$checkEmpty | bool | present for compatibility; empty values are currently treated as missing |
get
Return the value with key $key, optionally setting a default in the process.
public get(string $key): mixedIf $default is supplied and no value for $key is currently set in the session then the default value will be set in the session and then returned.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string |
set
Stores a cache value with optional per-value expiry.
public set(string $key, mixed $value, int $timeout): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
$value | mixed | value to store |
$timeout | int | optional per-value timeout in seconds |
remove
Removes a value from the current cache namespace.
public remove(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
clear
public clear(): boolClears all values from all applications.
This equates to a full session reset.
extend
Merges one or more arrays into the current cache namespace payload.
public extend(): voidtoArray
public toArray(): voidcount
Returns the number of entries in the current namespace.
public count(): intload
Loads a value from namespaced session storage while honoring per-value expiry.
private load(string $key): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | cache key |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:25 +0000