Skip to content
Permalink
Browse files

Make MemcachedEngine more friendly without php extension

  • Loading branch information...
Denys Kyselov
Denys Kyselov committed Jul 12, 2014
1 parent 6488669 commit 8f8b15d8d2846df2b8f6386b2e10abdc5622ef71
Showing with 13 additions and 13 deletions.
  1. +13 −13 src/Cache/Engine/MemcachedEngine.php
@@ -17,7 +17,6 @@
use Cake\Cache\CacheEngine;
use Cake\Error;
use Cake\Utility\Inflector;
use \Memcached;
/**
* Memcached storage engine for cache. Memcached has some limitations in the amount of
@@ -60,7 +59,7 @@ class MemcachedEngine extends CacheEngine {
* - `servers` String or array of memcached servers. If an array MemcacheEngine will use
* them as a pool.
* - `options` - Additional options for the memcached client. Should be an array of option => value.
* Use the Memcached::OPT_* constants as keys.
* Use the \Memcached::OPT_* constants as keys.
*
* @var array
*/
@@ -85,11 +84,7 @@ class MemcachedEngine extends CacheEngine {
*
* @var array
*/
protected $_serializers = [
'igbinary' => Memcached::SERIALIZER_IGBINARY,
'json' => Memcached::SERIALIZER_JSON,
'php' => Memcached::SERIALIZER_PHP
];
protected $_serializers = [];
/**
* Initialize the Cache Engine
@@ -101,16 +96,21 @@ class MemcachedEngine extends CacheEngine {
* @throws \Cake\Error\Exception when you try use authentication without Memcached compiled with SASL support
*/
public function init(array $config = []) {
if (!class_exists('Memcached')) {
if (!class_exists('\\Memcached')) {
return false;
}
if (!isset($config['prefix'])) {
$config['prefix'] = Inflector::slug(APP_DIR) . '_';
}
if (defined('Memcached::HAVE_MSGPACK') && Memcached::HAVE_MSGPACK) {
$this->_serializers['msgpack'] = Memcached::SERIALIZER_MSGPACK;
$this->_serializers = [
'igbinary' => \Memcached::SERIALIZER_IGBINARY,
'json' => \Memcached::SERIALIZER_JSON,
'php' => \Memcached::SERIALIZER_PHP
];
if (defined('\\Memcached::HAVE_MSGPACK') && \Memcached::HAVE_MSGPACK) {
$this->_serializers['msgpack'] = \Memcached::SERIALIZER_MSGPACK;
}
parent::init($config);
@@ -177,16 +177,16 @@ protected function _setOptions() {
);
}
if ($serializer !== 'php' && !constant('Memcached::HAVE_' . strtoupper($serializer))) {
if ($serializer !== 'php' && !constant('\\Memcached::HAVE_' . strtoupper($serializer))) {
throw new Error\Exception(
sprintf('Memcached extension is not compiled with %s support', $serializer)
);
}
$this->_Memcached->setOption(Memcached::OPT_SERIALIZER, $this->_serializers[$serializer]);
$this->_Memcached->setOption(\Memcached::OPT_SERIALIZER, $this->_serializers[$serializer]);
// Check for Amazon ElastiCache instance
if (defined('Memcached::OPT_CLIENT_MODE') && defined('Memcached::DYNAMIC_CLIENT_MODE')) {
if (defined('\\Memcached::OPT_CLIENT_MODE') && defined('\\Memcached::DYNAMIC_CLIENT_MODE')) {
$this->_Memcached->setOption(\Memcached::OPT_CLIENT_MODE, \Memcached::DYNAMIC_CLIENT_MODE);
}

0 comments on commit 8f8b15d

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