Update dependencies

This commit is contained in:
Chris Hunt
2024-02-16 21:36:54 +00:00
parent 22d7a59e59
commit d52ae0d3c3
9569 changed files with 460443 additions and 282416 deletions

View File

@@ -30,14 +30,15 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
{
use LoggerAwareTrait;
private $storeSerialized;
private $values = [];
private $expiries = [];
private $defaultLifetime;
private $maxLifetime;
private $maxItems;
private bool $storeSerialized;
private array $values = [];
private array $tags = [];
private array $expiries = [];
private int $defaultLifetime;
private float $maxLifetime;
private int $maxItems;
private static $createCacheItem;
private static \Closure $createCacheItem;
/**
* @param bool $storeSerialized Disabling serialization can lead to cache corruptions when storing mutable values but increases performance otherwise
@@ -56,12 +57,15 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
$this->storeSerialized = $storeSerialized;
$this->maxLifetime = $maxLifetime;
$this->maxItems = $maxItems;
self::$createCacheItem ?? self::$createCacheItem = \Closure::bind(
static function ($key, $value, $isHit) {
self::$createCacheItem ??= \Closure::bind(
static function ($key, $value, $isHit, $tags) {
$item = new CacheItem();
$item->key = $key;
$item->value = $value;
$item->isHit = $isHit;
if (null !== $tags) {
$item->metadata[CacheItem::METADATA_TAGS] = $tags;
}
return $item;
},
@@ -70,10 +74,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
);
}
/**
* {@inheritdoc}
*/
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null)
public function get(string $key, callable $callback, ?float $beta = null, ?array &$metadata = null): mixed
{
$item = $this->getItem($key);
$metadata = $item->getMetadata();
@@ -90,20 +91,12 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
return $item->get();
}
/**
* {@inheritdoc}
*/
public function delete(string $key): bool
{
return $this->deleteItem($key);
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function hasItem($key)
public function hasItem(mixed $key): bool
{
if (\is_string($key) && isset($this->expiries[$key]) && $this->expiries[$key] > microtime(true)) {
if ($this->maxItems) {
@@ -120,10 +113,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
return isset($this->expiries[$key]) && !$this->deleteItem($key);
}
/**
* {@inheritdoc}
*/
public function getItem($key)
public function getItem(mixed $key): CacheItem
{
if (!$isHit = $this->hasItem($key)) {
$value = null;
@@ -136,38 +126,25 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
$value = $this->storeSerialized ? $this->unfreeze($key, $isHit) : $this->values[$key];
}
return (self::$createCacheItem)($key, $value, $isHit);
return (self::$createCacheItem)($key, $value, $isHit, $this->tags[$key] ?? null);
}
/**
* {@inheritdoc}
*/
public function getItems(array $keys = [])
public function getItems(array $keys = []): iterable
{
\assert(self::validateKeys($keys));
return $this->generateItems($keys, microtime(true), self::$createCacheItem);
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function deleteItem($key)
public function deleteItem(mixed $key): bool
{
\assert('' !== CacheItem::validateKey($key));
unset($this->values[$key], $this->expiries[$key]);
unset($this->values[$key], $this->tags[$key], $this->expiries[$key]);
return true;
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function deleteItems(array $keys)
public function deleteItems(array $keys): bool
{
foreach ($keys as $key) {
$this->deleteItem($key);
@@ -176,12 +153,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
return true;
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function save(CacheItemInterface $item)
public function save(CacheItemInterface $item): bool
{
if (!$item instanceof CacheItem) {
return false;
@@ -213,7 +185,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
}
if ($this->maxItems) {
unset($this->values[$key]);
unset($this->values[$key], $this->tags[$key]);
// Iterate items and vacuum expired ones while we are at it
foreach ($this->values as $k => $v) {
@@ -221,49 +193,38 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
break;
}
unset($this->values[$k], $this->expiries[$k]);
unset($this->values[$k], $this->tags[$k], $this->expiries[$k]);
}
}
$this->values[$key] = $value;
$this->expiries[$key] = $expiry ?? \PHP_INT_MAX;
if (null === $this->tags[$key] = $item["\0*\0newMetadata"][CacheItem::METADATA_TAGS] ?? null) {
unset($this->tags[$key]);
}
return true;
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function saveDeferred(CacheItemInterface $item)
public function saveDeferred(CacheItemInterface $item): bool
{
return $this->save($item);
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function commit()
public function commit(): bool
{
return true;
}
/**
* {@inheritdoc}
*
* @return bool
*/
public function clear(string $prefix = '')
public function clear(string $prefix = ''): bool
{
if ('' !== $prefix) {
$now = microtime(true);
foreach ($this->values as $key => $value) {
if (!isset($this->expiries[$key]) || $this->expiries[$key] <= $now || 0 === strpos($key, $prefix)) {
unset($this->values[$key], $this->expiries[$key]);
if (!isset($this->expiries[$key]) || $this->expiries[$key] <= $now || str_starts_with($key, $prefix)) {
unset($this->values[$key], $this->tags[$key], $this->expiries[$key]);
}
}
@@ -272,17 +233,15 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
}
}
$this->values = $this->expiries = [];
$this->values = $this->tags = $this->expiries = [];
return true;
}
/**
* Returns all cached values, with cache miss as null.
*
* @return array
*/
public function getValues()
public function getValues(): array
{
if (!$this->storeSerialized) {
return $this->values;
@@ -302,7 +261,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
}
/**
* {@inheritdoc}
* @return void
*/
public function reset()
{
@@ -331,7 +290,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
}
unset($keys[$i]);
yield $key => $f($key, $value, $isHit);
yield $key => $f($key, $value, $isHit, $this->tags[$key] ?? null);
}
foreach ($keys as $key) {
@@ -339,7 +298,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
}
}
private function freeze($value, string $key)
private function freeze($value, string $key): string|int|float|bool|array|\UnitEnum|null
{
if (null === $value) {
return 'N;';
@@ -353,12 +312,12 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
try {
$serialized = serialize($value);
} catch (\Exception $e) {
unset($this->values[$key]);
unset($this->values[$key], $this->tags[$key]);
$type = get_debug_type($value);
$message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e, 'cache-adapter' => get_debug_type($this)]);
return;
return null;
}
// Keep value serialized if it contains any objects or any internal references
if ('C' === $serialized[0] || 'O' === $serialized[0] || preg_match('/;[OCRr]:[1-9]/', $serialized)) {
@@ -369,7 +328,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
return $value;
}
private function unfreeze(string $key, bool &$isHit)
private function unfreeze(string $key, bool &$isHit): mixed
{
if ('N;' === $value = $this->values[$key]) {
return null;