Very random micro-optimizations

This commit is contained in:
Jose Lorenzo Rodriguez 2012-04-23 23:29:32 -04:30
parent ed0c5a4746
commit 63c0c2c75f
6 changed files with 32 additions and 20 deletions

View file

@ -170,7 +170,7 @@ abstract class CacheEngine {
$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;
}

View file

@ -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');
}

View file

@ -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;

View file

@ -66,19 +66,21 @@ class MemcacheEngine extends CacheEngine {
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)) {

View file

@ -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');
}

View file

@ -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');
}