phasync
Cache / has

Method

Cache::has

Whether a value is stored under $key and has not expired.

Description#

public Cache::has(
    $key
): bool

Parameters#

$key

Return values#

bool

Errors / Exceptions#

ExceptionWhen
CacheKeyExceptionFor an invalid key

Examples#

Example 1A stored null and a missing key
use Swerve\Swerve;

phasync::run(function () {
    $cache = Swerve::cache();
    $cache->set('nothing', null);

    var_dump($cache->has('nothing'));         // stored, with the value null
    var_dump($cache->has('never-set'));
    var_dump($cache->get('nothing', 'default'));
});
Output
bool(true)
bool(false)
NULL