Skip to content

Commit

Permalink
populate defaultConfig in all cache adapters
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AD7six committed Nov 19, 2013
1 parent 872e982 commit fdde2bc
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 106 deletions.
17 changes: 1 addition & 16 deletions Cake/Cache/Cache.php
Expand Up @@ -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
Expand Down
24 changes: 16 additions & 8 deletions Cake/Cache/CacheEngine.php
Expand Up @@ -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
];

/**
Expand All @@ -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']);
Expand Down
24 changes: 12 additions & 12 deletions Cake/Cache/Engine/ApcEngine.php
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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']);
}
}
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
36 changes: 20 additions & 16 deletions Cake/Cache/Engine/FileEngine.php
Expand Up @@ -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
];

/**
Expand Down
44 changes: 24 additions & 20 deletions Cake/Cache/Engine/MemcachedEngine.php
Expand Up @@ -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'],
];

/**
Expand Down
42 changes: 22 additions & 20 deletions Cake/Cache/Engine/RedisEngine.php
Expand Up @@ -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
];

/**
Expand Down
31 changes: 17 additions & 14 deletions Cake/Cache/Engine/XcacheEngine.php
Expand Up @@ -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'
];
Expand Down Expand Up @@ -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];
Expand All @@ -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 {
Expand Down

0 comments on commit fdde2bc

Please sign in to comment.