Skip to content

ObjectStoreSessionPersistence

A SessionPersistenceInterface storing one object per session id in any ObjectStoreClientInterface.

Every object store holds a session the same way: derive a key from the id, write the encoded payload, read it back, delete it. That is provider-independent, so it lives here once and the provider packages supply only their client.

There is no garbage collection: an object store has no cheap way to enumerate expired sessions (see ListableFilesystemInterface for why these clients cannot list), so expiry belongs to a bucket lifecycle rule configured alongside the store rather than to a pass on the request path.

class ObjectStoreSessionPersistence implements SessionPersistenceInterface

ImplementsSessionPersistenceInterface
Since3.2.0
SourceObjectStoreSessionPersistence.php

public function __construct(ObjectStoreClientInterface $client, string $keyPrefix = 'sessions/', string $keySuffix = '.json', SessionCodecInterface $codec = new SessionCodec(…)): mixed

Defaults to the portable codec: for an object store the round-trip dominates, and a readable stored object is worth more than a compact one.

ParameterTypeDescription
$clientObjectStoreClientInterfaceThe store, already bound to its bucket or container.
$keyPrefixstringPrepended to every session id to form the object key.
$keySuffixstringAppended to it, e.g. ‘.json’ so the stored object is recognisable in a bucket listing.
$codecSessionCodecInterfaceDefaults to the portable codec: for an object store the round-trip dominates, and a readable stored object is worth more than a compact one.

Returns mixed

MethodDescription
delete(string $sid): voidDeletes the session’s object from the store.
load(string $sid): ?arrayFetches the session’s object from the store and decodes it.
save(string $sid, array<string, mixed> $data): void

public function delete(string $sid): void

Deletes the session’s object from the store.

Delegates straight to the client, which treats an absent key as a no-op.

ParameterTypeDescription
$sidstring

public function load(string $sid): ?array

Fetches the session’s object from the store and decodes it.

Returns null when the store has no object under the derived key or the object is empty; a missing key is an ordinary miss, not an error.

ParameterTypeDescription
$sidstring

Returns ?``array

public function save(string $sid, array<string, mixed> $data): void

ParameterTypeDescription
$sidstring
$dataarray``<``string``, ``mixed``>