Permalink
Browse files

Very random micro-optimizations

  • Loading branch information...
1 parent ed0c5a4 commit 63c0c2c75faea25b032945e3c71de7ae53a96eb1 @lorenzo lorenzo committed Apr 24, 2012
@@ -170,7 +170,7 @@ public function key($key) {
$prefix = vsprintf($this->_groupPrefix, $this->groups());
}
- $key = Inflector::underscore(str_replace(array(DS, '/', '.'), '_', strval($key)));
+ $key = preg_replace('/[\s]+/', '_', strtolower(trim(str_replace(array(DS, '/', '.'), '_', strval($key)))));
return $prefix . $key;
}
@@ -44,7 +44,11 @@ class ApcEngine extends CacheEngine {
* @see CacheEngine::__defaults
*/
public function init($settings = array()) {
- parent::init(array_merge(array('engine' => 'Apc', 'prefix' => Inflector::slug(APP_DIR) . '_'), $settings));
+ if (!isset($settings['prefix'])) {
+ $settings['prefix'] = Inflector::slug(APP_DIR) . '_';
+ }
+ $settings += array('engine' => 'Apc');
+ parent::init($settings);
return function_exists('apc_dec');
}
@@ -68,13 +68,16 @@ class FileEngine extends CacheEngine {
* @return boolean True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
- parent::init(array_merge(
- array(
- 'engine' => 'File', 'path' => CACHE, 'prefix' => 'cake_', 'lock' => true,
- 'serialize' => true, 'isWindows' => false, 'mask' => 0664
- ),
- $settings
- ));
+ $settings += array(
+ 'engine' => 'File',
+ 'path' => CACHE,
+ 'prefix' => 'cake_',
+ 'lock' => true,
+ 'serialize' => true,
+ 'isWindows' => false,
+ 'mask' => 0664
+ );
+ parent::init($settings);
if (DS === '\\') {
$this->settings['isWindows'] = true;
@@ -66,19 +66,21 @@ public function init($settings = array()) {
if (!class_exists('Memcache')) {
return false;
}
- parent::init(array_merge(array(
+ if (!isset($settings['prefix'])) {
+ $settings['prefix'] = Inflector::slug(APP_DIR) . '_';
+ }
+ $settings += array(
'engine' => 'Memcache',
- 'prefix' => Inflector::slug(APP_DIR) . '_',
'servers' => array('127.0.0.1'),
'compress' => false,
'persistent' => true
- ), $settings)
);
+ parent::init($settings);
if ($this->settings['compress']) {
$this->settings['compress'] = MEMCACHE_COMPRESSED;
}
- if (!is_array($this->settings['servers'])) {
+ if (is_string($this->settings['servers'])) {
$this->settings['servers'] = array($this->settings['servers']);
}
if (!isset($this->_Memcache)) {
@@ -45,10 +45,11 @@ class WincacheEngine extends CacheEngine {
* @see CacheEngine::__defaults
*/
public function init($settings = array()) {
- parent::init(array_merge(array(
- 'engine' => 'Wincache',
- 'prefix' => Inflector::slug(APP_DIR) . '_'),
- $settings));
+ if (!isset($settings['prefix'])) {
+ $settings['prefix'] = Inflector::slug(APP_DIR) . '_';
+ }
+ $settings += array('engine' => 'Wincache');
+ parent::init($settings);
return function_exists('wincache_ucache_info');
}
@@ -45,13 +45,15 @@ class XcacheEngine extends CacheEngine {
* @return boolean True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
- parent::init(array_merge(array(
+ if (!isset($settings['prefix'])) {
+ $settings['prefix'] = Inflector::slug(APP_DIR) . '_';
+ }
+ $settings += array(
'engine' => 'Xcache',
- 'prefix' => Inflector::slug(APP_DIR) . '_',
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'password'
- ), $settings)
);
+ parent::init($settings);
return function_exists('xcache_info');
}

0 comments on commit 63c0c2c

Please sign in to comment.