Method
Cache::set
Store $value under $key for every worker, for $ttl seconds or until evicted.
Description#
public Cache::set(
$key,
mixed $value,
$ttl = null
): boolThe value is serialized in the calling worker. Once this returns, every worker has been told to forget the key and fetches the new value when it next reads it.
Parameters#
- $key
- $value mixed
- $ttl = null
- Seconds, an interval, or null for no expiry; zero or less deletes the key
Return values#
False when the value is larger than the cache holds bool
Errors / Exceptions#
| Exception | When |
|---|---|
CacheKeyException | For an invalid key |
LogicException | Directly in swerve.php, which the worker serves after: a coroutine started there waits instead |
Examples#
Swerve::cache()->set("user.$id", $user, 60);See also#
Cache::getThe value stored under$key, or$defaultwhen there is none or it has expired.Cache::deleteRemove$keyfrom the cache of every worker.