Index: core/install/install_toolkit.php =================================================================== --- core/install/install_toolkit.php +++ core/install/install_toolkit.php @@ -970,7 +970,9 @@ $cache_handler = $this->Application->makeClass('kCache'); $cache_handlers = Array ( - 'Fake' => 'None', 'Memcache' => 'Memcached', 'XCache' => 'XCache', 'Apc' => 'Alternative PHP Cache' + 'Fake' => 'None', + 'Memcache' => 'Memcache', 'Memcached' => 'Memcached', + 'XCache' => 'XCache', 'Apc' => 'Alternative PHP Cache', ); foreach ($cache_handlers AS $class_prefix => $title) { Index: core/kernel/utility/cache.php =================================================================== --- core/kernel/utility/cache.php +++ core/kernel/utility/cache.php @@ -104,6 +104,10 @@ // get cache handler class to use $handler_class = kUtil::getSystemConfig()->get('CacheHandler', '') . 'CacheHandler'; + if ( $handler_class == 'MemcacheCacheHandler' && version_compare(PHP_VERSION, '7.0.0', '>=') ) { + $handler_class = 'MemcachedCacheHandler'; + } + // defined cache handler doesn't exist -> use default if ( !class_exists($handler_class) ) { $handler_class = 'FakeCacheHandler'; @@ -823,6 +827,114 @@ } } + class MemcachedCacheHandler extends kCacheHandler { + + /** + * Memcache connection + * + * @var Memcache + * @access protected + */ + protected $_handler = null; + + /** + * MemcachedCacheHandler constructor. + * + * @param kCache $parent Parent. + * @param string $default_servers Default servers. + */ + public function __construct(kCache $parent, $default_servers = '') + { + parent::__construct($parent); + + $this->cachingType = CACHING_TYPE_MEMORY; + + $memcached_servers = kUtil::getSystemConfig()->get('MemcacheServers', $default_servers); + + if ( $memcached_servers && class_exists('Memcached') ) { + $this->_enabled = true; + $this->_handler = new Memcached(); + $servers = explode(';', $memcached_servers); + + foreach ( $servers as $server ) { + if ( preg_match('/(.*):([\d]+)$/', $server, $regs) ) { + // Possible format: "hostname:port" OR "unix:///path/to/socket:0". + $server = $regs[1]; + $port = $regs[2]; + } + else { + $port = 11211; + } + + $this->_handler->addServer($server, $port); + } + + // Verify, that memcache server is working. + if ( !$this->_handler->set('test', 1) ) { + $this->_enabled = false; + } + } + } + + /** + * Retrieves value from cache + * + * @param string $name Name. + * + * @return mixed + * @access public + */ + public function get($name) + { + return $this->_handler->get($name); + } + + /** + * Stores value in cache + * + * @param string $name Name. + * @param mixed $value Value. + * @param integer $expiration Expiration. + * + * @return boolean + * @access public + */ + public function set($name, $value, $expiration = 0) + { + // 0 - don't use compression. + return $this->_handler->set($name, $value, 0, $expiration); + } + + /** + * Stores value in cache (only if it's not there already) + * + * @param string $name Name. + * @param mixed $value Value. + * @param integer $expiration Expiration. + * + * @return boolean + * @access public + */ + public function add($name, $value, $expiration = 0) + { + // 0 - don't use compression. + return $this->_handler->add($name, $value, 0, $expiration); + } + + /** + * Deletes key from cache + * + * @param string $name Name. + * + * @return boolean + * @access public + */ + public function delete($name) + { + return $this->_handler->delete($name, 0); + } + + } class ApcCacheHandler extends kCacheHandler { @@ -974,4 +1086,4 @@ { return xcache_unset($name); } - } \ No newline at end of file + }