Skip to main content
Version: Fegg 5.x

Cache::set

Keep a value

Description​

public static bool Cache::set( string $key, mixed $value, int $ttl )

Keeps $value for $ttl seconds, replacing the value of $key. The file is written to a temporary name and then renamed.

Returns false when the directory or the file cannot be written (a warning is logged).

Throws \InvalidArgumentException when $ttl is below 1 or $value contains an object other than \DateTime / \DateTimeImmutable (see Values).

Arguments​

NameData typeDefaultRemarks
$keystringName of the value
$valuemixedArrays, scalars, null and dates
$ttlintSeconds to keep it (at least 1)

Example​

Controller
use Fegg\Tool\Cache;

Cache::set('ranking', array(
'items' => $items,
'updated' => new \DateTimeImmutable(),
), 3600);