<commit_before><?php
/**
 * Memcached storage engine for cache
 *
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       Cake.Cache.Engine
 * @since         CakePHP(tm) v 1.2.0.4933
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * Memcached storage engine for cache.  Memcached has some limitations in the amount of
 * control you have over expire times far in the future.  See MemcacheEngine::write() for
 * more information.
 *
 * Cache::clear() is not implemented due to lack of support from memcached api
 * If clear() support is primordial to you, use the default memcache engine
 *
 * Main advantage of this Memcached engine over the Memcache engine is
 * support of binary protocol, and igbibnary serialization
 * (if memcached extension compiled with --enable-igbinary)
 * Compressed keys can also be incremented/decremented
 *
 * @package       Cake.Cache.Engine
 */
class MemcachedEngine extends CacheEngine {

/**
 * Memcache wrapper.
 *
 * @var Memcache
 */
	protected $_Memcached = null;

/**
 * @var string Keyname of the cache entry holding all the others key name
 */
	protected $_keys = '_keys';

/**
 * @var string Token used to separe each keyname in the $_keys string
 */
	protected $_keySeparator = '|';

/**
 * Settings
 *
 *  - servers = string or array of memcache servers, default => 127.0.0.1. If an
 *    array MemcacheEngine will use them as a pool.
 *  - compress = boolean, default => false
 *
 * @var array
 */
	public $settings = array();

/**
 * Initialize the Cache Engine
 *
 * Called automatically by the cache frontend
 * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
 *
 * @param array $settings array of setting for the engine
 * @return boolean True if the engine has been successfully initialized, false if not
 */
	public function init($settings = array()) {
		if (!class_exists('Memcached')) {
			return false;
		}
		if (!isset($settings['prefix'])) {
			$settings['prefix'] = Inflector::slug(APP_DIR) . '_';
		}
		$settings += array(
			'engine' => 'Memcached',
			'servers' => array('127.0.0.1'),
			'compress' => false,
			'persistent' => true,
			'persistent_id' => 'mc'
		);
		parent::init($settings);

		$this->_keys .= $this->settings['prefix'];

		if (!is_array($this->settings['servers'])) {
			$this->settings['servers'] = array($this->settings['servers']);
		}
		if (!isset($this->_Memcached)) {
			$this->_Memcached = new Memcached($this->settings['persistent'] ? $this->settings['persistent_id'] : null);
			$this->_setOptions();

			if (!count($this->_Memcached->getServerList())) {
				$servers = array();
				foreach ($this->settings['servers'] as $server) {
					$servers[] = $this->_parseServerString($server);
				}


				if ($this->_Memcached->addServers($servers)) {
					if (!$this->_Memcached->get($this->_keys)) {
						$this->_Memcached->set($this->_keys, '');
					}
					return true;
				}
				return false;
			}

			return true;
		}

		return true;
	}

/**
 * Settings the memcached instance
 *
 */
	protected function _setOptions()
	{
		$this->_Memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
		$this->_Memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);

		if (Memcached::HAVE_IGBINARY) {
			$this->_Memcached->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_IGBINARY);
		}

		$this->_Memcached->setOption(Memcached::OPT_COMPRESSION, (bool)$this->settings['compress']);
	}

/**
 * Parses the server address into the host/port. Handles both IPv6 and IPv4
 * addresses and Unix sockets
 *
 * @param string $server The server address string.
 * @return array Array containing host, port
 */
	protected function _parseServerString($server) {
		if ($server[0] == 'u') {
			return array($server, 0);
		}
		if (substr($server, 0, 1) == '[') {
			$position = strpos($server, ']:');
			if ($position !== false) {
				$position++;
			}
		} else {
			$position = strpos($server, ':');
		}
		$port = 11211;
		$host = $server;
		if ($position !== false) {<commit_msg>Add support for SASL authentication<commit_after><?php
/**
 * Memcached storage engine for cache
 *
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       Cake.Cache.Engine
 * @since         CakePHP(tm) v 1.2.0.4933
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * Memcached storage engine for cache.  Memcached has some limitations in the amount of
 * control you have over expire times far in the future.  See MemcacheEngine::write() for
 * more information.
 *
 * Cache::clear() is not implemented due to lack of support from memcached api
 * If clear() support is primordial to you, use the default memcache engine
 *
 * Main advantage of this Memcached engine over the Memcache engine is
 * support of binary protocol, and igbibnary serialization
 * (if memcached extension compiled with --enable-igbinary)
 * Compressed keys can also be incremented/decremented
 *
 * @package       Cake.Cache.Engine
 */
class MemcachedEngine extends CacheEngine {

/**
 * Memcache wrapper.
 *
 * @var Memcache
 */
	protected $_Memcached = null;

/**
 * @var string Keyname of the cache entry holding all the others key name
 */
	protected $_keys = '_keys';

/**
 * @var string Token used to separe each keyname in the $_keys string
 */
	protected $_keySeparator = '|';

/**
 * Settings
 *
 *  - servers = string or array of memcache servers, default => 127.0.0.1. If an
 *    array MemcacheEngine will use them as a pool.
 *  - compress = boolean, default => false
 *
 * @var array
 */
	public $settings = array();

/**
 * Initialize the Cache Engine
 *
 * Called automatically by the cache frontend
 * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
 *
 * @param array $settings array of setting for the engine
 * @return boolean True if the engine has been successfully initialized, false if not
 */
	public function init($settings = array()) {
		if (!class_exists('Memcached')) {
			return false;
		}
		if (!isset($settings['prefix'])) {
			$settings['prefix'] = Inflector::slug(APP_DIR) . '_';
		}
		$settings += array(
			'engine' => 'Memcached',
			'servers' => array('127.0.0.1'),
			'compress' => false,
			'persistent' => true,
			'persistent_id' => 'mc'
			'login' => null,
			'password' => <PASSWORD>,
		);
		parent::init($settings);

		$this->_keys .= $this->settings['prefix'];

		if (!is_array($this->settings['servers'])) {
			$this->settings['servers'] = array($this->settings['servers']);
		}
		if (!isset($this->_Memcached)) {
			$this->_Memcached = new Memcached($this->settings['persistent'] ? $this->settings['persistent_id'] : null);
			$this->_setOptions();

			if (!count($this->_Memcached->getServerList())) {
				$servers = array();
				foreach ($this->settings['servers'] as $server) {
					$servers[] = $this->_parseServerString($server);
				}


				if ($this->_Memcached->addServers($servers)) {
					if (!$this->_Memcached->get($this->_keys)) {
						$this->_Memcached->set($this->_keys, '');
					}
					return true;
				}
				return false;
			}

			return true;
		}

		return true;
	}

/**
 * Settings the memcached instance
 *
 */
	protected function _setOptions()
	{
		$this->_Memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
		$this->_Memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);

		if (Memcached::HAVE_IGBINARY) {
			$this->_Memcached->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_IGBINARY);
		}

		$this->_Memcached->setOption(Memcached::OPT_COMPRESSION, (bool)$this->settings['compress']);

		if ($this->settings['login'] !== null && $this->settings['password'] !== null) {
			$this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']);
		}
	}

/**
 * Parses the server address into the host/port. Handles both IPv6 and IPv4
 * addresses and Unix sockets
 *
 * @param string $server The server address string.
 * @return array Array containing host, port
 */
	protected function _parseServerString($server) {
		if ($server[0] == 'u') {
			return array($server, 0);
		}
		if (substr($server, 0, 1) == '[') {
			$position = strpos($server, ']:');
			if ($position !== false) {
				$position++;
			}
		} else {
			$position = strpos($server, ':');
		}
		$port = 11211;
		$host = $server;
		if ($position !== false) {
{'fraction_non_alphanumeric': 0.15163441565540614, 'fraction_numerical': 0.010276593418607193, 'mean_word_length': 3.7571502860114405, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '506695', 'n_tokens_mistral': 3087, 'n_tokens_neox': 2768, 'n_words': 791}