Skip to content

Commit

Permalink
Convert CacheEngine to use InstanceConfigSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
AD7six committed Mar 29, 2014
1 parent 3f2cf76 commit 27baf04
Showing 1 changed file with 5 additions and 32 deletions.
37 changes: 5 additions & 32 deletions src/Cache/CacheEngine.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\Cache;

use Cake\Core\InstanceConfigTrait;
use Cake\Utility\Inflector;

/**
Expand All @@ -22,14 +23,7 @@
*/
abstract class CacheEngine {

/**
* Runtime config
*
* This is the config of a particular instance
*
* @var array
*/
protected $_config = [];
use InstanceConfigTrait;

/**
* The default cache configuration is overriden in most cache adapters. These are
Expand Down Expand Up @@ -70,14 +64,16 @@ abstract class CacheEngine {
* @return boolean True if the engine has been successfully initialized, false if not
*/
public function init($config = []) {
$this->_config = $config + $this->_defaultConfig;
$this->config($config);

if (!empty($this->_config['groups'])) {
sort($this->_config['groups']);
$this->_groupPrefix = str_repeat('%s_', count($this->_config['groups']));
}
if (!is_numeric($this->_config['duration'])) {
$this->_config['duration'] = strtotime($this->_config['duration']) - time();
}

return true;
}

Expand Down Expand Up @@ -166,29 +162,6 @@ public function groups() {
return $this->_config['groups'];
}

/**
* Cache Engine config
*
* If called with no arguments, returns the full config array
* Otherwise returns the config for the specified key
*
* Usage:
* {{{
* $instance->config(); will return full config
* $instance->config('duration'); will return configured duration
* $instance->config('notset'); will return null
* }}}
*
* @param string|null $key to return
* @return mixed array or config value
*/
public function config($key = null) {
if ($key === null) {
return $this->_config;
}
return isset($this->_config[$key]) ? $this->_config[$key] : null;
}

/**
* Generates a safe key for use with cache engine storage engines.
*
Expand Down

0 comments on commit 27baf04

Please sign in to comment.