phasync
Cache / setMultiple

Method

Cache::setMultiple

Store several values, by key, with one $ttl, as Cache::set does.

Description#

public Cache::setMultiple(
    $values,
    $ttl = null
): bool

Parameters#

$values
$ttl = null
Seconds, an interval, or null for no expiry; zero or less deletes the keys

Return values#

False when a value is larger than the cache holds bool

Errors / Exceptions#

ExceptionWhen
CacheKeyExceptionFor an invalid key
LogicExceptionDirectly in swerve.php, which the worker serves after: a coroutine started there waits instead

Examples#

Example 1Several values with one ttl
use Swerve\Swerve;

phasync::run(function () {
    $cache = Swerve::cache();

    $cache->setMultiple(['a' => 1, 'b' => 2, 'c' => 3], new DateInterval('PT5M'));   // one ttl for all

    var_export($cache->getMultiple(['a', 'b', 'x'], 'none'));
    echo "\n";
});
Output
array (
  'a' => 1,
  'b' => 2,
  'x' => 'none',
)