phasync
Cache / delete

Method

Cache::delete

Remove $key from the cache of every worker.

Description#

public Cache::delete(
    $key
): bool

Parameters#

$key

Return values#

True, also when there was nothing to remove 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 1Delete one key, or several
use Swerve\Swerve;

phasync::run(function () {
    $cache = Swerve::cache();
    $cache->setMultiple(['session.1' => 'ann', 'session.2' => 'bob', 'session.3' => 'cy']);

    $cache->delete('session.1');                          // in every worker
    $cache->deleteMultiple(['session.2', 'not-there']);    // true, also for a key not there

    var_export($cache->getMultiple(['session.1', 'session.2', 'session.3']));
    echo "\n";
});
Output
array (
  'session.1' => NULL,
  'session.2' => NULL,
  'session.3' => 'cy',
)