<commit_before><?php
/* SVN FILE: $Id$ */
/**
 * Caching for CakePHP.
 *
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
 * Copyright 2005-2008, Cake Software Foundation, Inc.
 *								1785 E. Sahara Avenue, Suite 490-204
 *								Las Vegas, Nevada 89104
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright		Copyright 2005-2008, Cake Software Foundation, Inc.
 * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package			cake
 * @subpackage		cake.cake.libs
 * @since			CakePHP(tm) v 1.2.0.4933
 * @version			$Revision$
 * @modifiedby		$LastChangedBy$
 * @lastmodified	$Date$
 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
 */
/**
 * Included libraries.
 */
/**
 * Caching for CakePHP.
 *
 * @package		cake
 * @subpackage	cake.cake.libs
 */
class Cache extends Object {
/**
 * Cache engine to use
 *
 * @var object
 * @access protected
 */
	var $_Engine = null;
/**
 * Cache configuration stack
 *
 * @var array
 * @access private
 */
	var $__config = array();
/**
 * Holds name of the current configuration being used
 *
 * @var array
 * @access private
 */
	var $__name = 'default';
/**
 * whether to reset the settings with the next call to self::set();
 *
 * @var array
 * @access private
 */
	var $__reset = false;
/**
 * Returns a singleton instance
 *
 * @return object
 * @access public
 */
	function &getInstance() {
		static $instance = array();
		if (!$instance) {
			$instance[0] =& new Cache();
		}
		return $instance[0];
	}
/**
 * Tries to find and include a file for a cache engine and returns object instance
 *
 * @param $name	Name of the engine (without 'Engine')
 * @return mixed $engine object or null
 * @access private
 */
	function __loadEngine($name) {
		if (!class_exists($name . 'Engine')) {
			require LIBS . DS . 'cache' . DS . strtolower($name) . '.php';
		}
		return true;
	}
/**
 * Set the cache configuration to use
 *
 * @see app/config/core.php for configuration settings
 * @param string $name Name of the configuration
 * @param array $settings Optional associative array of settings passed to the engine
 * @return array(engine, settings) on success, false on failure
 * @access public
 */
	function config($name = null, $settings = array()) {
		$_this =& Cache::getInstance();
		if (is_array($name)) {
			$settings = $name;
		}

		if ($name === null || !is_string($name)) {
			$name = $_this->__name;
		}

		$current = array();
		if (isset($_this->__config[$name])) {
			$current = $_this->__config[$name];
		}

		if (!empty($settings)) {
			$_this->__name = null;
			$_this->__config[$name] = array_merge($current, $settings);
		}

		if (empty($_this->__config[$name]['engine'])) {
			return false;
		}

		$_this->__name = $name;
		$engine = $_this->__config[$name]['engine'];

		if (!$_this->isInitialized($engine)) {
			if ($_this->engine($engine, $_this->__config[$name]) === false) {
				return false;
			}
			$settings = $_this->__config[$name] = $_this->settings($engine);
		} else {
			$settings = $_this->__config[$name] = $_this->set($_this->__config[$name]);
		}
		return compact('engine', 'settings');
	}
/**
 * Set the cache engine to use or modify settings for one instance
 *
 * @param string $name Name of the engine (without 'Engine')
 * @param array $settings Optional associative array of settings passed to the engine
 * @return boolean True on success, false on failure
 * @access public
 */
	function engine($name = 'File', $settings = array()) {
		if (!$name || Configure::read('Cache.disable')) {
			return false;
		}

		$cacheClass = $name . 'Engine';
		$_this =& Cache::getInstance();
		if (!isset($_this->_Engine[$name])) {
			if ($_this->__loadEngine($name) === false) {
				return false;
			}
			$_this->_Engine[$name] =& new $cacheClass();
		}

		if ($_this->_Engine[$name]->init($settings)) {
			if (time() % $_this->_Engine[$name]->settings['probability'] === 0) {
				$_this->_Engine[$name]->gc();
			}
			return true;
		}
		$_this->_Engine[$name] = null;
		return false;
	}
/**
 * Sets current config options. if no params are passed, resets settings if needed
 *
 * @param mixed $settings Optional string for simple name-value pair or array
 * @param string $value Optional for a simple name-value pair
 * @return void
 * @access public
 */
	function set($settings = array(), $value = null) {
		$_this =& Cache::getInstance();
		if (!isset($_this->__config[$_this->__name])) {
			return false;
		}

		$engine = $_this->__config[$_this->__name]['engine'];

		if (!empty($settings)) {
			$_this->__reset = true;
		}

		if ($_this->__reset === true) {
			if (empty($settings)) {
				$_this->__reset = false;
				$settings = $_this->__config[$_this->__name];
			} else {
				if (is_string($settings) && $value !== null) {
					$settings = array($settings => $value);
				}
				$settings = array_merge($_this->__config[$_this->__name], $settings);
			}
			$_this->_Engine[$engine]->init($settings);
		}<commit_msg>updating doc block for Cache::set() refs #5460<commit_after><?php
/* SVN FILE: $Id$ */
/**
 * Caching for CakePHP.
 *
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
 * Copyright 2005-2008, Cake Software Foundation, Inc.
 *								1785 E. Sahara Avenue, Suite 490-204
 *								Las Vegas, Nevada 89104
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright		Copyright 2005-2008, Cake Software Foundation, Inc.
 * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package			cake
 * @subpackage		cake.cake.libs
 * @since			CakePHP(tm) v 1.2.0.4933
 * @version			$Revision$
 * @modifiedby		$LastChangedBy$
 * @lastmodified	$Date$
 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
 */
/**
 * Included libraries.
 */
/**
 * Caching for CakePHP.
 *
 * @package		cake
 * @subpackage	cake.cake.libs
 */
class Cache extends Object {
/**
 * Cache engine to use
 *
 * @var object
 * @access protected
 */
	var $_Engine = null;
/**
 * Cache configuration stack
 *
 * @var array
 * @access private
 */
	var $__config = array();
/**
 * Holds name of the current configuration being used
 *
 * @var array
 * @access private
 */
	var $__name = 'default';
/**
 * whether to reset the settings with the next call to self::set();
 *
 * @var array
 * @access private
 */
	var $__reset = false;
/**
 * Returns a singleton instance
 *
 * @return object
 * @access public
 */
	function &getInstance() {
		static $instance = array();
		if (!$instance) {
			$instance[0] =& new Cache();
		}
		return $instance[0];
	}
/**
 * Tries to find and include a file for a cache engine and returns object instance
 *
 * @param $name	Name of the engine (without 'Engine')
 * @return mixed $engine object or null
 * @access private
 */
	function __loadEngine($name) {
		if (!class_exists($name . 'Engine')) {
			require LIBS . DS . 'cache' . DS . strtolower($name) . '.php';
		}
		return true;
	}
/**
 * Set the cache configuration to use
 *
 * @see app/config/core.php for configuration settings
 * @param string $name Name of the configuration
 * @param array $settings Optional associative array of settings passed to the engine
 * @return array(engine, settings) on success, false on failure
 * @access public
 */
	function config($name = null, $settings = array()) {
		$_this =& Cache::getInstance();
		if (is_array($name)) {
			$settings = $name;
		}

		if ($name === null || !is_string($name)) {
			$name = $_this->__name;
		}

		$current = array();
		if (isset($_this->__config[$name])) {
			$current = $_this->__config[$name];
		}

		if (!empty($settings)) {
			$_this->__name = null;
			$_this->__config[$name] = array_merge($current, $settings);
		}

		if (empty($_this->__config[$name]['engine'])) {
			return false;
		}

		$_this->__name = $name;
		$engine = $_this->__config[$name]['engine'];

		if (!$_this->isInitialized($engine)) {
			if ($_this->engine($engine, $_this->__config[$name]) === false) {
				return false;
			}
			$settings = $_this->__config[$name] = $_this->settings($engine);
		} else {
			$settings = $_this->__config[$name] = $_this->set($_this->__config[$name]);
		}
		return compact('engine', 'settings');
	}
/**
 * Set the cache engine to use or modify settings for one instance
 *
 * @param string $name Name of the engine (without 'Engine')
 * @param array $settings Optional associative array of settings passed to the engine
 * @return boolean True on success, false on failure
 * @access public
 */
	function engine($name = 'File', $settings = array()) {
		if (!$name || Configure::read('Cache.disable')) {
			return false;
		}

		$cacheClass = $name . 'Engine';
		$_this =& Cache::getInstance();
		if (!isset($_this->_Engine[$name])) {
			if ($_this->__loadEngine($name) === false) {
				return false;
			}
			$_this->_Engine[$name] =& new $cacheClass();
		}

		if ($_this->_Engine[$name]->init($settings)) {
			if (time() % $_this->_Engine[$name]->settings['probability'] === 0) {
				$_this->_Engine[$name]->gc();
			}
			return true;
		}
		$_this->_Engine[$name] = null;
		return false;
	}
/**
 * Temporarily change settings to current config options. if no params are passed, resets settings if needed
 * Cache::write() will reset the configuration changes made
 *
 * @param mixed $settings Optional string for simple name-value pair or array
 * @param string $value Optional for a simple name-value pair
 * @return void
 * @access public
 */
	function set($settings = array(), $value = null) {
		$_this =& Cache::getInstance();
		if (!isset($_this->__config[$_this->__name])) {
			return false;
		}

		$engine = $_this->__config[$_this->__name]['engine'];

		if (!empty($settings)) {
			$_this->__reset = true;
		}

		if ($_this->__reset === true) {
			if (empty($settings)) {
				$_this->__reset = false;
				$settings = $_this->__config[$_this->__name];
			} else {
				if (is_string($settings) && $value !== null) {
					$settings = array($settings => $value);
				}
				$settings = array_merge($_this->__config[$_this->__name], $settings);
			}
			$_this->_Engine[$engine]->init($settings);
		}
{'fraction_non_alphanumeric': 0.1671033478893741, 'fraction_numerical': 0.008733624454148471, 'mean_word_length': 3.566238369517058, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 2, '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': '1831970', 'n_tokens_mistral': 3633, 'n_tokens_neox': 3217, 'n_words': 940}