diff --git a/Cache.php b/Cache.php index fabf32a3a..0c8d8d37f 100644 --- a/Cache.php +++ b/Cache.php @@ -71,7 +71,7 @@ class Cache * An array mapping URL schemes to fully qualified caching engine * class names. * - * @var string[] + * @var array * @psalm-var array */ protected static $_dsnClassMap = [ @@ -85,7 +85,7 @@ class Cache ]; /** - * Flag for tracking whether or not caching is enabled. + * Flag for tracking whether caching is enabled. * * @var bool */ @@ -94,7 +94,7 @@ class Cache /** * Group to Config mapping * - * @var array + * @var array */ protected static $_groups = []; @@ -466,7 +466,7 @@ public static function clear(string $config = 'default'): bool /** * Delete all keys from the cache from all configurations. * - * @return bool[] Status code. For each configuration, it reports the status of the operation + * @return array Status code. For each configuration, it reports the status of the operation */ public static function clearAll(): array { @@ -503,8 +503,8 @@ public static function clearGroup(string $group, string $config = 'default'): bo * $configs will equal to `['posts' => ['daily', 'weekly']]` * Calling this method will load all the configured engines. * - * @param string|null $group group name or null to retrieve all group mappings - * @return array map of group and all configuration that has the same group + * @param string|null $group Group name or null to retrieve all group mappings + * @return array Map of group and all configuration that has the same group * @throws \Cake\Cache\InvalidArgumentException */ public static function groupConfigs(?string $group = null): array @@ -548,7 +548,7 @@ public static function disable(): void } /** - * Check whether or not caching is enabled. + * Check whether caching is enabled. * * @return bool */ @@ -579,9 +579,8 @@ public static function enabled(): bool * the cache key is empty. Can be any callable type supported by your PHP. * @param string $config The cache configuration to use for this operation. * Defaults to default. - * @return mixed If the key is found: the cached data, false if the data - * missing/expired, or an error. If the key is not found: boolean of the - * success of the write + * @return mixed If the key is found: the cached data. + * If the key is not found the value returned by the callable. */ public static function remember(string $key, callable $callable, string $config = 'default') { diff --git a/CacheEngine.php b/CacheEngine.php index 56db69536..ed01098e3 100644 --- a/CacheEngine.php +++ b/CacheEngine.php @@ -49,7 +49,7 @@ abstract class CacheEngine implements CacheInterface, CacheEngineInterface * - `warnOnWriteFailures` Some engines, such as ApcuEngine, may raise warnings on * write failures. * - * @var array + * @var array */ protected $_defaultConfig = [ 'duration' => 3600, @@ -72,7 +72,7 @@ abstract class CacheEngine implements CacheInterface, CacheEngineInterface * Called automatically by the cache frontend. Merge the runtime config with the defaults * before use. * - * @param array $config Associative array of parameters for the engine + * @param array $config Associative array of parameters for the engine * @return bool True if the engine has been successfully initialized, false if not */ public function init(array $config = []): bool @@ -187,7 +187,11 @@ public function setMultiple($values, $ttl = null): bool } /** - * Deletes multiple cache items in a single operation. + * Deletes multiple cache items as a list + * + * This is a best effort attempt. If deleting an item would + * create an error it will be ignored, and all items will + * be attempted. * * @param iterable $keys A list of string-based keys to be deleted. * @return bool True if the items were successfully removed. False if there was an error. @@ -198,14 +202,14 @@ public function deleteMultiple($keys): bool { $this->ensureValidType($keys); + $result = true; foreach ($keys as $key) { - $result = $this->delete($key); - if ($result === false) { - return false; + if (!$this->delete($key)) { + $result = false; } } - return true; + return $result; } /** @@ -317,7 +321,7 @@ abstract public function clearGroup(string $group): bool; * and returns the `group value` for each of them, this is * the token representing each group in the cache key * - * @return string[] + * @return array */ public function groups(): array { diff --git a/CacheRegistry.php b/CacheRegistry.php index fb6d0ab06..1c5aa4660 100644 --- a/CacheRegistry.php +++ b/CacheRegistry.php @@ -24,7 +24,7 @@ /** * An object registry for cache engines. * - * Used by Cake\Cache\Cache to load and manage cache engines. + * Used by {@link \Cake\Cache\Cache} to load and manage cache engines. * * @extends \Cake\Core\ObjectRegistry<\Cake\Cache\CacheEngine> */ @@ -64,9 +64,9 @@ protected function _throwMissingClassError(string $class, ?string $plugin): void * * Part of the template method for Cake\Core\ObjectRegistry::load() * - * @param string|\Cake\Cache\CacheEngine $class The classname or object to make. + * @param \Cake\Cache\CacheEngine|string $class The classname or object to make. * @param string $alias The alias of the object. - * @param array $config An array of settings to use for the cache engine. + * @param array $config An array of settings to use for the cache engine. * @return \Cake\Cache\CacheEngine The constructed CacheEngine class. * @throws \RuntimeException when an object doesn't implement the correct interface. */ diff --git a/Engine/ApcuEngine.php b/Engine/ApcuEngine.php index 170ea4a43..bc90e8f0f 100644 --- a/Engine/ApcuEngine.php +++ b/Engine/ApcuEngine.php @@ -29,7 +29,7 @@ class ApcuEngine extends CacheEngine * Contains the compiled group names * (prefixed with the global configuration prefix) * - * @var string[] + * @var array */ protected $_compiledGroupNames = []; @@ -38,7 +38,7 @@ class ApcuEngine extends CacheEngine * * Called automatically by the cache frontend * - * @param array $config array of setting for the engine + * @param array $config array of setting for the engine * @return bool True if the engine has been successfully initialized, false if not */ public function init(array $config = []): bool @@ -183,7 +183,7 @@ public function add(string $key, $value): bool * If the group initial value was not found, then it initializes * the group accordingly. * - * @return string[] + * @return array * @link https://secure.php.net/manual/en/function.apcu-fetch.php * @link https://secure.php.net/manual/en/function.apcu-store.php */ diff --git a/Engine/ArrayEngine.php b/Engine/ArrayEngine.php index c33608204..9050537eb 100644 --- a/Engine/ArrayEngine.php +++ b/Engine/ArrayEngine.php @@ -152,7 +152,7 @@ public function clear(): bool * If the group initial value was not found, then it initializes * the group accordingly. * - * @return string[] + * @return array */ public function groups(): array { diff --git a/Engine/FileEngine.php b/Engine/FileEngine.php index 22ec33ce0..46a7f187a 100644 --- a/Engine/FileEngine.php +++ b/Engine/FileEngine.php @@ -57,7 +57,7 @@ class FileEngine extends CacheEngine * cache::gc from ever being called automatically. * - `serialize` Should cache objects be serialized first. * - * @var array + * @var array */ protected $_defaultConfig = [ 'duration' => 3600, @@ -81,7 +81,7 @@ class FileEngine extends CacheEngine * * Called automatically by the cache frontend. * - * @param array $config array of setting for the engine + * @param array $config array of setting for the engine * @return bool True if the engine has been successfully initialized, false if not */ public function init(array $config = []): bool @@ -223,6 +223,10 @@ public function delete($key): bool $path = $this->_File->getRealPath(); $this->_File = null; + if ($path === false) { + return false; + } + // phpcs:disable return @unlink($path); // phpcs:enable diff --git a/Engine/MemcachedEngine.php b/Engine/MemcachedEngine.php index 781c4cfc7..b714f5056 100644 --- a/Engine/MemcachedEngine.php +++ b/Engine/MemcachedEngine.php @@ -60,7 +60,7 @@ class MemcachedEngine extends CacheEngine * - `options` - Additional options for the memcached client. Should be an array of option => value. * Use the \Memcached::OPT_* constants as keys. * - * @var array + * @var array */ protected $_defaultConfig = [ 'compress' => false, @@ -82,12 +82,12 @@ class MemcachedEngine extends CacheEngine * * Memcached must be compiled with JSON and igbinary support to use these engines * - * @var array + * @var array */ protected $_serializers = []; /** - * @var string[] + * @var array */ protected $_compiledGroupNames = []; @@ -96,7 +96,7 @@ class MemcachedEngine extends CacheEngine * * Called automatically by the cache frontend * - * @param array $config array of setting for the engine + * @param array $config array of setting for the engine * @return bool True if the engine has been successfully initialized, false if not * @throws \InvalidArgumentException When you try use authentication without * Memcached compiled with SASL support @@ -134,11 +134,6 @@ public function init(array $config = []): bool $this->_config['servers'] = [$this->_config['servers']]; } - /** @psalm-suppress RedundantPropertyInitializationCheck */ - if (isset($this->_Memcached)) { - return true; - } - if ($this->_config['persistent']) { $this->_Memcached = new Memcached($this->_config['persistent']); } else { @@ -470,7 +465,7 @@ public function add(string $key, $value): bool * If the group initial value was not found, then it initializes * the group accordingly. * - * @return string[] + * @return array */ public function groups(): array { diff --git a/Engine/RedisEngine.php b/Engine/RedisEngine.php index 1eeed8cad..b7f0fec4b 100644 --- a/Engine/RedisEngine.php +++ b/Engine/RedisEngine.php @@ -51,7 +51,7 @@ class RedisEngine extends CacheEngine * - `timeout` timeout in seconds (float). * - `unix_socket` Path to the unix socket file (default: false) * - * @var array + * @var array */ protected $_defaultConfig = [ 'database' => 0, @@ -72,7 +72,7 @@ class RedisEngine extends CacheEngine * * Called automatically by the cache frontend * - * @param array $config array of setting for the engine + * @param array $config array of setting for the engine * @return bool True if the engine has been successfully initialized, false if not */ public function init(array $config = []): bool @@ -283,7 +283,7 @@ public function add(string $key, $value): bool * If the group initial value was not found, then it initializes * the group accordingly. * - * @return string[] + * @return array */ public function groups(): array { diff --git a/Engine/WincacheEngine.php b/Engine/WincacheEngine.php index 9d9e36eb6..ca0388e4b 100644 --- a/Engine/WincacheEngine.php +++ b/Engine/WincacheEngine.php @@ -30,7 +30,7 @@ class WincacheEngine extends CacheEngine * Contains the compiled group names * (prefixed with the global configuration prefix) * - * @var array + * @var array */ protected $_compiledGroupNames = []; @@ -39,7 +39,7 @@ class WincacheEngine extends CacheEngine * * Called automatically by the cache frontend * - * @param array $config array of setting for the engine + * @param array $config array of setting for the engine * @return bool True if the engine has been successfully initialized, false if not */ public function init(array $config = []): bool @@ -155,7 +155,7 @@ public function clear(): bool * If the group initial value was not found, then it initializes * the group accordingly. * - * @return string[] + * @return array */ public function groups(): array { diff --git a/composer.json b/composer.json index f78e504ab..001a8a9dc 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "require": { "php": ">=7.2.0", "cakephp/core": "^4.0", - "psr/simple-cache": "^1.0.0" + "psr/simple-cache": "^1.0 || ^2.0" }, "provide": { "psr/simple-cache-implementation": "^1.0.0"