Exception
CacheKeyException
A key Swerve::cache can't take: PSR-16 keys are non-empty strings without {}()/\@:.
Introduction#
It is a \InvalidArgumentException and a PSR-16 InvalidArgumentException.
Class synopsis#
final class CacheKeyException extends InvalidArgumentException implements \Stringable, \Throwable, InvalidArgumentException, CacheException {
}Examples#
use Swerve\CacheKeyException;
use Swerve\Swerve;
phasync::run(function () {
foreach (['user.1', 'user:1', '', 'a/b'] as $key) {
try {
Swerve::cache()->get($key);
echo "'$key' is a key\n";
} catch (CacheKeyException $e) {
echo "'$key' is not: ", $e->getMessage(), "\n";
}
}
});Output
'user.1' is a key
'user:1' is not: A cache key is a non-empty string without {}()/\@:, not 'user:1'
'' is not: A cache key is a non-empty string without {}()/\@:, not ''
'a/b' is not: A cache key is a non-empty string without {}()/\@:, not 'a/b'try {
Swerve::cache()->get('user:1'); // ':' is not allowed in a key
} catch (CacheKeyException $e) {
Swerve::cache()->get('user.1');
}See also#
CacheThe cache every worker shares, from Swerve::cache(): a PSR-16 cache held by the master process, the least recently used entries evicted past --cache-size.