Skip to content
Permalink
Browse files

Cache: Use extension_loaded() instead of *_exists()

1. extension_loaded() is slightly faster than function|class_exists()
2. Standardize the code block, don't do parent::init() before
extension_loaded() check.
  • Loading branch information...
FrankFFFF committed Mar 26, 2015
1 parent 8708599 commit f5e75b80c7d336de0da880d5930ddcc824167ff4
@@ -42,8 +42,12 @@ class ApcEngine extends CacheEngine
*/
public function init(array $config = [])
{
if (!extension_loaded('apc')) {
return false;
}
parent::init($config);
return function_exists('apc_dec');
return true;
}
/**
@@ -101,7 +101,7 @@ class MemcachedEngine extends CacheEngine
*/
public function init(array $config = [])
{
if (!class_exists('Memcached')) {
if (!extension_loaded('memcached')) {
return false;
}
@@ -76,11 +76,11 @@ class RedisEngine extends CacheEngine
*/
public function init(array $config = [])
{
if (!class_exists('Redis')) {
if (!extension_loaded('redis')) {
return false;
}
parent::init($config);
parent::init($config);
return $this->_connect();
}
@@ -42,8 +42,12 @@ class WincacheEngine extends CacheEngine
*/
public function init(array $config = [])
{
if (!extension_loaded('wincache')) {
return false;
}
parent::init($config);
return function_exists('wincache_ucache_info');
return true;
}
/**
@@ -58,11 +58,12 @@ class XcacheEngine extends CacheEngine
*/
public function init(array $config = [])
{
if (php_sapi_name() !== 'cli') {
parent::init($config);
return function_exists('xcache_info');
if (!extension_loaded('xcache') || php_sapi_name() === 'cli') {
return false;
}
return false;
parent::init($config);
return true;
}
/**

0 comments on commit f5e75b8

Please sign in to comment.
You can’t perform that action at this time.