<commit_before><?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\caching;

use yii\base\Component;
use yii\helpers\StringHelper;

/**
 * Cache is the base class for cache classes supporting different cache storage implementation.
 *
 * A data item can be stored in cache by calling [[set()]] and be retrieved back
 * later (in the same or different request) by [[get()]]. In both operations,
 * a key identifying the data item is required. An expiration time and/or a [[Dependency|dependency]]
 * can also be specified when calling [[set()]]. If the data item expires or the dependency
 * changes at the time of calling [[get()]], the cache will return no data.
 *
 * A typical usage pattern of cache is like the following:
 *
 * ~~~
 * $key = 'demo';
 * $data = $cache->get($key);
 * if ($data === false) {
 *     // ...generate $data here...
 *     $cache->set($key, $data, $expire, $dependency);
 * }
 * ~~~
 *
 * Because Cache implements the ArrayAccess interface, it can be used like an array. For example,
 *
 * ~~~
 * $cache['foo'] = 'some data';
 * echo $cache['foo'];
 * ~~~
 *
 * Derived classes should implement the following methods:
 *
 * - [[getValue()]]: retrieve the value with a key (if any) from cache
 * - [[setValue()]]: store the value with a key into cache
 * - [[addValue()]]: store the value only if the cache does not have this key before
 * - [[deleteValue()]]: delete the value with the specified key from cache
 * - [[flushValues()]]: delete all values from cache
 *
 *
 * @author <NAME> <<EMAIL>>
 * @since 2.0
 */
abstract class Cache extends Component implements \ArrayAccess
{
	/**
	 * @var string a string prefixed to every cache key so that it is unique. Defaults to null, meaning using
	 * the value of [[Application::id]] as the key prefix. You may set this property to be an empty string
	 * if you don't want to use key prefix. It is recommended that you explicitly set this property to some
	 * static value if the cached data needs to be shared among multiple applications.
	 */
	public $keyPrefix;
	/**
	 * @var array|boolean the functions used to serialize and unserialize cached data. Defaults to null, meaning
	 * using the default PHP `serialize()` and `unserialize()` functions. If you want to use some more efficient
	 * serializer (e.g. [igbinary](http://pecl.php.net/package/igbinary)), you may configure this property with
	 * a two-element array. The first element specifies the serialization function, and the second the deserialization
	 * function. If this property is set false, data will be directly sent to and retrieved from the underlying
	 * cache component without any serialization or deserialization. You should not turn off serialization if
	 * you are using [[Dependency|cache dependency]], because it relies on data serialization.
	 */
	public $serializer;


	/**
	 * Initializes the application component.
	 * This method overrides the parent implementation by setting default cache key prefix.
	 */
	public function init()
	{
		parent::init();
		if ($this->keyPrefix === null) {
			$this->keyPrefix = \Yii::$app->id;
		}
	}

	/**
	 * Builds a normalized cache key from a given key.
	 *
	 * The generated key contains letters and digits only, and its length is no more than 32.
	 * 
	 * If the given key is a string containing alphanumeric characters only and no more than 32 characters,
	 * then the key will be returned back without change. Otherwise, a normalized key
	 * is generated by serializing the given key and applying MD5 hashing.
	 * 
	 * The following example builds a cache key using three parameters:
	 *
	 * ~~~
	 * $key = $cache->buildKey($className, $method, $id);
	 * ~~~
	 *
	 * @param array|string $key the key to be normalized
	 * @return string the generated cache key
	 */
	public function buildKey($key)<commit_msg>Update Cache.php<commit_after><?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\caching;

use yii\base\Component;
use yii\helpers\StringHelper;

/**
 * Cache is the base class for cache classes supporting different cache storage implementation.
 *
 * A data item can be stored in cache by calling [[set()]] and be retrieved back
 * later (in the same or different request) by [[get()]]. In both operations,
 * a key identifying the data item is required. An expiration time and/or a [[Dependency|dependency]]
 * can also be specified when calling [[set()]]. If the data item expires or the dependency
 * changes at the time of calling [[get()]], the cache will return no data.
 *
 * A typical usage pattern of cache is like the following:
 *
 * ~~~
 * $key = 'demo';
 * $data = $cache->get($key);
 * if ($data === false) {
 *     // ...generate $data here...
 *     $cache->set($key, $data, $expire, $dependency);
 * }
 * ~~~
 *
 * Because Cache implements the ArrayAccess interface, it can be used like an array. For example,
 *
 * ~~~
 * $cache['foo'] = 'some data';
 * echo $cache['foo'];
 * ~~~
 *
 * Derived classes should implement the following methods:
 *
 * - [[getValue()]]: retrieve the value with a key (if any) from cache
 * - [[setValue()]]: store the value with a key into cache
 * - [[addValue()]]: store the value only if the cache does not have this key before
 * - [[deleteValue()]]: delete the value with the specified key from cache
 * - [[flushValues()]]: delete all values from cache
 *
 *
 * @author <NAME> <<EMAIL>>
 * @since 2.0
 */
abstract class Cache extends Component implements \ArrayAccess
{
	/**
	 * @var string a string prefixed to every cache key so that it is unique. Defaults to null, meaning using
	 * the value of [[Application::id]] as the key prefix. You may set this property to be an empty string
	 * if you don't want to use key prefix. It is recommended that you explicitly set this property to some
	 * static value if the cached data needs to be shared among multiple applications.
	 */
	public $keyPrefix;
	/**
	 * @var array|boolean the functions used to serialize and unserialize cached data. Defaults to null, meaning
	 * using the default PHP `serialize()` and `unserialize()` functions. If you want to use some more efficient
	 * serializer (e.g. [igbinary](http://pecl.php.net/package/igbinary)), you may configure this property with
	 * a two-element array. The first element specifies the serialization function, and the second the deserialization
	 * function. If this property is set false, data will be directly sent to and retrieved from the underlying
	 * cache component without any serialization or deserialization. You should not turn off serialization if
	 * you are using [[Dependency|cache dependency]], because it relies on data serialization.
	 */
	public $serializer;


	/**
	 * Initializes the application component.
	 * This method overrides the parent implementation by setting default cache key prefix.
	 */
	public function init()
	{
		parent::init();
		if ($this->keyPrefix === null) {
			$this->keyPrefix = \Yii::$app->id;
		}
	}

	/**
	 * Builds a normalized cache key from a given key.
	 *
	 * The generated key contains letters and digits only, and its length is no more than 32.
	 * 
	 * If the given key is a string containing alphanumeric characters only and no more than 32 characters,
	 * then the key will be returned back without change. Otherwise, a normalized key
	 * is generated by serializing the given key and applying MD5 hashing.
	 * 
	 * The following example builds a cache key using three parameters:
	 *
	 * ~~~
	 * $key = $cache->buildKey(array($className, $method, $id));
	 * ~~~
	 *
	 * @param array|string $key the key to be normalized
	 * @return string the generated cache key
	 */
	public function buildKey($key)
{'fraction_non_alphanumeric': 0.10804275897174853, 'fraction_numerical': 0.002799694578773225, 'mean_word_length': 3.6863446630888492, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5769651', 'n_tokens_mistral': 2192, 'n_tokens_neox': 2068, 'n_words': 1012}