Index: branches/5.2.x/core/install/install_toolkit.php =================================================================== --- branches/5.2.x/core/install/install_toolkit.php +++ branches/5.2.x/core/install/install_toolkit.php @@ -970,7 +970,11 @@ $cache_handler = $this->Application->makeClass('kCache'); $cache_handlers = Array ( - 'Fake' => 'None', 'Memcache' => 'Memcached', 'XCache' => 'XCache', 'Apc' => 'Alternative PHP Cache' + 'Fake' => 'None', + 'Memcached' => 'Memcached (via "Memcached" extension)', + 'Memcache' => 'Memcached (via "Memcache" extension)', + 'XCache' => 'XCache', + 'Apc' => 'Alternative PHP Cache', ); foreach ($cache_handlers AS $class_prefix => $title) { Index: branches/5.2.x/core/kernel/utility/cache.php =================================================================== --- branches/5.2.x/core/kernel/utility/cache.php +++ branches/5.2.x/core/kernel/utility/cache.php @@ -823,6 +823,116 @@ } } + class MemcachedCacheHandler extends kCacheHandler { + + /** + * Memcache connection + * + * @var Memcached + * @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|array $name Name. + * + * @return mixed + * @access public + */ + public function get($name) + { + if ( is_array($name) ) { + return $this->_handler->getMulti($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) + { + return $this->_handler->set($name, $value, $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) + { + return $this->_handler->add($name, $value, $expiration); + } + + /** + * Deletes key from cache + * + * @param string $name Name. + * + * @return boolean + * @access public + */ + public function delete($name) + { + return $this->_handler->delete($name); + } + + } class ApcCacheHandler extends kCacheHandler { @@ -974,4 +1084,4 @@ { return xcache_unset($name); } - } \ No newline at end of file + }