Cache
Cache
CSession backend using a cache system.
Implements the SessionBackend interface to provide session storage using a cache backend. This class handles storing, retrieving, and managing session data via a caching mechanism, improving performance and scalability for session management.
Properties
session
public CacheAdapter $sessionconfig
private array $configsessionID
public string $sessionIDidentity
public string $identityMethods
__construct
public __construct(array $config): voidParameters
| Parameter | Type | Description |
|---|---|---|
$config | array |
isEmpty
Checks if the session is empty.
public isEmpty(): boolReturns true if the session ID is not set or the session data is null, indicating that there is no active session.
read
Reads the current session data and returns it as an array.
public read(): voidhas
Checks if the specified session key exists.
public has(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the session key to check for existence |
get
Retrieves a value from the session using the specified key.
public get(string $key): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key identifying the session value to retrieve |
set
Sets a value in the session using the provided key.
public set(string $key, mixed $value): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key under which the value will be stored in the session |
$value | mixed | the value to store in the session |
Removes a value from the session storage by its key.
public (string $key): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key identifying the session value to remove |
clear
Clears all data from the current session.
public clear(): voidThis method invokes the clear operation on the session object, if it exists, effectively removing all session data stored in the backend cache.
getToken
Retrieves the current session token.
public getToken(): ?stringcreate
Creates a new session for the given identity and initializes it with optional data.
public create(string $identity, array $data): voidGenerates a unique session ID using a SHA-256 hash of a unique string based on the identity. Instantiates a new CacheAdapter for session storage and populates it with the provided data.
Parameters
| Parameter | Type | Description |
|---|---|---|
$identity | string | The unique identifier for the session (e.g., user ID). |
$data | array | optional associative array of session data to initialize the session with |
refresh
Refreshes the session token.
public refresh(string $token): ?stringParameters
| Parameter | Type | Description |
|---|---|---|
$token | string | the session token to refresh |
load
Loads the session data for the given token.
public load(string $token, ?array $sessionData): boolInitializes the session using the specified cache adapter and configuration, then reads the session data into the provided reference variable.
Parameters
| Parameter | Type | Description |
|---|---|---|
$token | string | the session token to load |
$sessionData | array |
getIdentity
Retrieves the identity associated with the current session.
public getIdentity(): ?stringGenerated by Hazaar API Doc Generator on Sun, 01 Mar 2026 09:22:26 +0000