From fdde2bc9533a372b769893fa81a9011cdf626399 Mon Sep 17 00:00:00 2001 From: AD7six Date: Tue, 19 Nov 2013 10:27:16 +0000 Subject: [PATCH] populate defaultConfig in all cache adapters Remove the duplicate document block from `Cache` as it will most likely get out of sync with Core cache engine config (it is already out of sync, missing keys). Sort all the keys in defaultConfig so that it's easier to fine keys/see differences. Remove defaults from the docblock for the defaultConfig property - it will only duplicate the actual property value and most likely get out of sync. --- Cake/Cache/Cache.php | 17 +---------- Cake/Cache/CacheEngine.php | 24 ++++++++++----- Cake/Cache/Engine/ApcEngine.php | 24 +++++++-------- Cake/Cache/Engine/FileEngine.php | 36 ++++++++++++---------- Cake/Cache/Engine/MemcachedEngine.php | 44 +++++++++++++++------------ Cake/Cache/Engine/RedisEngine.php | 42 +++++++++++++------------ Cake/Cache/Engine/XcacheEngine.php | 31 ++++++++++--------- 7 files changed, 112 insertions(+), 106 deletions(-) diff --git a/Cake/Cache/Cache.php b/Cake/Cache/Cache.php index 5811b3b522f..8ac054d6421 100644 --- a/Cake/Cache/Cache.php +++ b/Cake/Cache/Cache.php @@ -57,22 +57,7 @@ * This engine is recommended to people deploying on windows with IIS. * - `RedisEngine` - Uses redis and php-redis extension to store cache data. * - * The following keys are used in core cache engines: - * - * - `duration` Specify how long items in this cache configuration last. - * - `groups` List of groups or 'tags' associated to every key stored in this config. - * handy for deleting a complete group from cache. - * - `prefix` Prefix appended to all entries. Good for when you need to share a keyspace - * with either another cache config or another application. - * - `probability` Probability of hitting a cache gc cleanup. Setting to 0 will disable - * cache::gc from ever being called automatically. - * - `servers' Used by memcache. Give the address of the memcached servers to use. - * - `compress` Used by memcache. Enables memcache's compressed format. - * - `serialize` Used by FileCache. Should cache objects be serialized first. - * - `path` Used by FileCache. Path to where cachefiles should be saved. - * - `lock` Used by FileCache. Should files be locked before writing to them? - * - `user` Used by Xcache. Username for XCache - * - `password` Used by Xcache/Redis. Password for XCache/Redis + * See Cache engine documentation for expected configuration keys. * * @see app/Config/core.php for configuration settings * @param string $name Name of the configuration diff --git a/Cake/Cache/CacheEngine.php b/Cake/Cache/CacheEngine.php index 873680143c3..76dfe1295d6 100644 --- a/Cake/Cache/CacheEngine.php +++ b/Cake/Cache/CacheEngine.php @@ -23,25 +23,33 @@ abstract class CacheEngine { /** - * Settings of current engine instance + * Runtime config + * + * This is the config of a particular instance * * @var array */ protected $_config = []; /** - * Default configuration + * The default cache configuration is overriden in most cache adapters. These are + * the keys that are common to all adapters. If overriden, this property is not used. * - * These settings apply to all cache engines, and can be overriden by a specific cache - * engine or runtime config + * - `duration` Specify how long items in this cache configuration last. + * - `groups` List of groups or 'tags' associated to every key stored in this config. + * handy for deleting a complete group from cache. + * - `prefix` Prefix appended to all entries. Good for when you need to share a keyspace + * with either another cache config or another application. + * - `probability` Probability of hitting a cache gc cleanup. Setting to 0 will disable + * cache::gc from ever being called automatically. * * @var array */ protected static $_defaultConfig = [ - 'prefix' => 'cake_', 'duration' => 3600, - 'probability' => 100, - 'groups' => [] + 'groups' => [], + 'prefix' => 'cake_', + 'probability' => 100 ]; /** @@ -62,7 +70,7 @@ abstract class CacheEngine { * @return boolean True if the engine has been successfully initialized, false if not */ public function init($config = []) { - $config += $this->_config + static::$_defaultConfig + self::$_defaultConfig; + $config += $this->_config + static::$_defaultConfig; $this->_config = $config; if (!empty($this->_config['groups'])) { sort($this->_config['groups']); diff --git a/Cake/Cache/Engine/ApcEngine.php b/Cake/Cache/Engine/ApcEngine.php index 73f10180286..9f8a0d9ae62 100644 --- a/Cake/Cache/Engine/ApcEngine.php +++ b/Cake/Cache/Engine/ApcEngine.php @@ -36,14 +36,14 @@ class ApcEngine extends CacheEngine { * * Called automatically by the cache frontend * - * @param array $settings array of setting for the engine + * @param array $config array of setting for the engine * @return boolean True if the engine has been successfully initialized, false if not */ - public function init($settings = []) { - if (!isset($settings['prefix'])) { - $settings['prefix'] = Inflector::slug(APP_DIR) . '_'; + public function init($config = []) { + if (!isset($config['prefix'])) { + $config['prefix'] = Inflector::slug(APP_DIR) . '_'; } - parent::init($settings); + parent::init($config); return function_exists('apc_dec'); } @@ -73,7 +73,7 @@ public function write($key, $value, $duration) { public function read($key) { $time = time(); $cachetime = intval(apc_fetch($key . '_expires')); - if ($cachetime !== 0 && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) { + if ($cachetime !== 0 && ($cachetime < $time || ($time + $this->_config['duration']) < $cachetime)) { return false; } return apc_fetch($key); @@ -126,7 +126,7 @@ public function clear($check) { $cacheKeys = $info['cache_list']; unset($info); foreach ($cacheKeys as $key) { - if (strpos($key['info'], $this->settings['prefix']) === 0) { + if (strpos($key['info'], $this->_config['prefix']) === 0) { apc_delete($key['info']); } } @@ -142,13 +142,13 @@ public function clear($check) { */ public function groups() { if (empty($this->_compiledGroupNames)) { - foreach ($this->settings['groups'] as $group) { - $this->_compiledGroupNames[] = $this->settings['prefix'] . $group; + foreach ($this->_config['groups'] as $group) { + $this->_compiledGroupNames[] = $this->_config['prefix'] . $group; } } $groups = apc_fetch($this->_compiledGroupNames); - if (count($groups) !== count($this->settings['groups'])) { + if (count($groups) !== count($this->_config['groups'])) { foreach ($this->_compiledGroupNames as $group) { if (!isset($groups[$group])) { apc_store($group, 1); @@ -160,7 +160,7 @@ public function groups() { $result = []; $groups = array_values($groups); - foreach ($this->settings['groups'] as $i => $group) { + foreach ($this->_config['groups'] as $i => $group) { $result[] = $group . $groups[$i]; } return $result; @@ -173,7 +173,7 @@ public function groups() { * @return boolean success */ public function clearGroup($group) { - apc_inc($this->settings['prefix'] . $group, 1, $success); + apc_inc($this->_config['prefix'] . $group, 1, $success); return $success; } diff --git a/Cake/Cache/Engine/FileEngine.php b/Cake/Cache/Engine/FileEngine.php index 6073bb9c0b9..f1b0dd2b0fd 100644 --- a/Cake/Cache/Engine/FileEngine.php +++ b/Cake/Cache/Engine/FileEngine.php @@ -45,29 +45,33 @@ class FileEngine extends CacheEngine { protected $_File = null; /** - * Settings + * The defaults used unless overriden by runtime configuration * - * - path = absolute path to cache directory, default => CACHE - * - prefix = string prefix for filename, default => cake_ - * - lock = enable file locking on write, default => true - * - serialize = serialize the data, default => true + * - `duration` Specify how long items in this cache configuration last. + * - `groups` List of groups or 'tags' associated to every key stored in this config. + * handy for deleting a complete group from cache. + * - `isWindows` Automatically populated with whether the host is windows or not + * - `lock` Used by FileCache. Should files be locked before writing to them? + * - `mask` The mask used for created files + * - `path` Path to where cachefiles should be saved. + * - `prefix` Prepended to all entries. Good for when you need to share a keyspace + * with either another cache config or another application. + * - `probability` Probability of hitting a cache gc cleanup. Setting to 0 will disable + * cache::gc from ever being called automatically. + * - `serialize` Should cache objects be serialized first. * * @var array - */ - protected $_config = []; - -/** - * _defaultConfig - * - * @var mixed */ protected static $_defaultConfig = [ + 'duration' => 3600, + 'groups' => [], + 'isWindows' => false, + 'lock' => true, + 'mask' => 0664, 'path' => CACHE, 'prefix' => 'cake_', - 'lock' => true, - 'serialize' => true, - 'isWindows' => false, - 'mask' => 0664 + 'probability' => 100, + 'serialize' => true ]; /** diff --git a/Cake/Cache/Engine/MemcachedEngine.php b/Cake/Cache/Engine/MemcachedEngine.php index d9094015c00..aeff883cae7 100644 --- a/Cake/Cache/Engine/MemcachedEngine.php +++ b/Cake/Cache/Engine/MemcachedEngine.php @@ -40,35 +40,39 @@ class MemcachedEngine extends CacheEngine { protected $_Memcached = null; /** - * Settings + * The defaults used unless overriden by runtime configuration * - * - servers = string or array of memcached servers, default => 127.0.0.1. If an - * array MemcacheEngine will use them as a pool. - * - compress = boolean, default => false - * - persistent = string The name of the persistent connection. All configurations using + * - `compress` Whether to compress data + * - `duration` Specify how long items in this cache configuration last. + * - `groups` List of groups or 'tags' associated to every key stored in this config. + * handy for deleting a complete group from cache. + * - `login` Login to access the Memcache server + * - `password` Password to access the Memcache server + * - `persistent` The name of the persistent connection. All configurations using * the same persistent value will share a single underlying connection. - * - serialize = string, default => php. The serializer engine used to serialize data. - * Available engines are php, igbinary and json. Beside php, the memcached extension - * must be compiled with the appropriate serializer support. - * - * @var array - */ - protected $_config = []; - -/** - * Default config - * - * The defaults used unless overriden by runtime configuration + * - `prefix` Prepended to all entries. Good for when you need to share a keyspace + * with either another cache config or another application. + * - `probability` Probability of hitting a cache gc cleanup. Setting to 0 will disable + * cache::gc from ever being called automatically. + * - `serialize` The serializer engine used to serialize data. Available engines are php, + * igbinary and json. Beside php, the memcached extension must be compiled with the + * appropriate serializer support. + * - `servers` String or array of memcached servers. If an array MemcacheEngine will use + * them as a pool. * * @var array */ protected static $_defaultConfig = [ - 'servers' => ['127.0.0.1'], 'compress' => false, - 'persistent' => false, + 'duration' => 3600, + 'groups' => [], 'login' => null, 'password' => null, - 'serialize' => 'php' + 'persistent' => false, + 'prefix' => 'cake_', + 'probability' => 100, + 'serialize' => 'php', + 'servers' => ['127.0.0.1'], ]; /** diff --git a/Cake/Cache/Engine/RedisEngine.php b/Cake/Cache/Engine/RedisEngine.php index 9901c52248c..0d1f973e452 100644 --- a/Cake/Cache/Engine/RedisEngine.php +++ b/Cake/Cache/Engine/RedisEngine.php @@ -31,33 +31,35 @@ class RedisEngine extends CacheEngine { protected $_Redis = null; /** - * Settings - * - * - server = string URL or ip to the Redis server host - * - database = integer database number to use for connection - * - port = integer port number to the Redis server (default: 6379) - * - timeout = float timeout in seconds (default: 0) - * - persistent = boolean Connects to the Redis server with a persistent connection (default: true) - * - * @var array - */ - protected $_config = []; - -/** - * Default config - * * The defaults used unless overriden by runtime configuration * + * - `database` database number to use for connection. + * - `duration` Specify how long items in this cache configuration last. + * - `groups` List of groups or 'tags' associated to every key stored in this config. + * handy for deleting a complete group from cache. + * - `password` Redis server password. + * - `persistent` Connect to the Redis server with a persistent connection + * - `port` port number to the Redis server. + * - `prefix` Prefix appended to all entries. Good for when you need to share a keyspace + * with either another cache config or another application. + * - `probability` Probability of hitting a cache gc cleanup. Setting to 0 will disable + * cache::gc from ever being called automatically. + * - `server` URL or ip to the Redis server host. + * - `timeout` timeout in seconds (float). + * * @var array */ protected static $_defaultConfig = [ - 'prefix' => null, - 'server' => '127.0.0.1', 'database' => 0, - 'port' => 6379, + 'duration' => 3600, + 'groups' => [], 'password' => false, - 'timeout' => 0, - 'persistent' => true + 'persistent' => true, + 'port' => 6379, + 'prefix' => null, + 'probability' => 100, + 'server' => '127.0.0.1', + 'timeout' => 0 ]; /** diff --git a/Cake/Cache/Engine/XcacheEngine.php b/Cake/Cache/Engine/XcacheEngine.php index 792c9a87e95..ee7bfb89cc4 100644 --- a/Cake/Cache/Engine/XcacheEngine.php +++ b/Cake/Cache/Engine/XcacheEngine.php @@ -28,22 +28,25 @@ class XcacheEngine extends CacheEngine { /** - * Settings - * - * - PHP_AUTH_USER = xcache.admin.user, default cake - * - PHP_AUTH_PW = xcache.admin.password, default cake - * - * @var array - */ - protected $_config = []; - -/** - * Default config + * The defaults used unless overriden by runtime configuration + * + * - `duration` Specify how long items in this cache configuration last. + * - `groups` List of groups or 'tags' associated to every key stored in this config. + * handy for deleting a complete group from cache. + * - `prefix` Prefix appended to all entries. Good for when you need to share a keyspace + * with either another cache config or another application. + * - `probability` Probability of hitting a cache gc cleanup. Setting to 0 will disable + * cache::gc from ever being called automatically. + * - `PHP_AUTH_USER` xcache.admin.user + * - `PHP_AUTH_PW` xcache.admin.password * * @var array */ protected static $_defaultConfig = [ + 'duration' => 3600, + 'groups' => [], 'prefix' => null, + 'probability' => 100, 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'password' ]; @@ -192,7 +195,7 @@ public function clearGroup($group) { protected function _auth($reverse = false) { static $backup = []; $keys = ['PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'password']; - foreach ($keys as $key => $setting) { + foreach ($keys as $key => $value) { if ($reverse) { if (isset($backup[$key])) { $_SERVER[$key] = $backup[$key]; @@ -205,8 +208,8 @@ protected function _auth($reverse = false) { if (!empty($value)) { $backup[$key] = $value; } - if (!empty($this->_config[$setting])) { - $_SERVER[$key] = $this->_config[$setting]; + if (!empty($this->_config[$value])) { + $_SERVER[$key] = $this->_config[$value]; } elseif (!empty($this->_config[$key])) { $_SERVER[$key] = $this->_config[$key]; } else {