Neuron-PHP

Memory
in package
implements IRepository

In-memory repository implementation for testing and development.

The Memory repository stores data in a PHP array with automatic expiration support.

Note: Data is lost when the PHP process ends. For persistent storage, use Redis or File repository implementations.

Tags
example
$repo = new Memory();
$repo->save('temp:data', ['foo' => 'bar'], 60);
$data = $repo->find('temp:data');

Table of Contents

Interfaces

IRepository
Repository interface for storing and retrieving serializable data.

Properties

$expiration  : array<string|int, mixed>
$storage  : array<string|int, mixed>

Methods

clear()  : void
Clear all data from the repository.
delete()  : bool
Delete a value by key.
exists()  : bool
Check if a key exists in the repository.
find()  : mixed
Find a value by key.
keys()  : array<string|int, mixed>
Get all keys in the repository (including expired).
save()  : bool
Save a value to memory.
isExpired()  : bool
Check if a key has expired.

Properties

$expiration

private array<string|int, mixed> $expiration = []

$storage

private array<string|int, mixed> $storage = []

Methods

clear()

Clear all data from the repository.

public clear() : void

delete()

Delete a value by key.

public delete(string $key) : bool
Parameters
$key : string

The key to delete

Return values
bool

True if deleted, false if key didn't exist

exists()

Check if a key exists in the repository.

public exists(string $key) : bool
Parameters
$key : string

The key to check

Return values
bool

True if exists and not expired, false otherwise

find()

Find a value by key.

public find(string $key) : mixed
Parameters
$key : string

The key to look up

Return values
mixed

The stored value, or null if not found or expired

keys()

Get all keys in the repository (including expired).

public keys() : array<string|int, mixed>
Return values
array<string|int, mixed>

save()

Save a value to memory.

public save(string $key, mixed $value[, int $ttl = 0 ]) : bool
Parameters
$key : string

The unique key to store the value under

$value : mixed

The value to store

$ttl : int = 0

Time-to-live in seconds (0 = no expiration)

Return values
bool

Always returns true

isExpired()

Check if a key has expired.

private isExpired(string $key) : bool
Parameters
$key : string

The key to check

Return values
bool

True if expired, false otherwise


        
On this page

Search results