<commit_before><?php

namespace mako\cache
{
	use \mako\cache\Exception as CacheException;
	
	/**
	* File based cache adapter.
	*
	* @author     <NAME>
	* @copyright  (c) 2008-2011 <NAME>
	* @license    http://www.makoframework.com/license
	*/

	class File extends \mako\cache\Adapter
	{
		//---------------------------------------------
		// Class variables
		//---------------------------------------------

		/**
		* Cache path.
		*/

		protected $path;

		//---------------------------------------------
		// Class constructor, destructor etc ...
		//---------------------------------------------

		/**
		* Constructor.
		*
		* @access  public
		* @param   array   Configuration
		*/

		public function __construct(array $config)
		{
			parent::__construct($config['identifier']);
			
			$this->path = $config['path'];

			if(file_exists($this->path) === false || is_readable($this->path) === false || is_writable($this->path) === false)
			{
				throw new CacheException(__CLASS__.': Cache directory is not writable.');
			}
		}

		//---------------------------------------------
		// Class methods
		//---------------------------------------------

		/**
		* Store variable in the cache.
		*
		* @access  public
		* @param   string   Cache key
		* @param   mixed    The variable to store
		* @param   int      (optional) Time to live
		* @return  boolean
		*/

		public function write($key, $value, $ttl = 0)
		{
			$ttl = (((int) $ttl === 0) ? 31556926 : (int) $ttl) + time();

			$data = "<?php defined('MAKO_APPLICATION') or die();return array('lifetime' => {$ttl}, 'data' => '".addslashes(serialize($value))."');";

			return is_int(file_put_contents("{$this->path}/mako_{$this->identifier}_{$key}.php", $data, LOCK_EX));
		}

		/**
		* Fetch variable from the cache.
		*
		* @access  public
		* @param   string  Cache key
		* @return  mixed
		*/

		public function read($key)
		{
			if(file_exists("{$this->path}/mako_{$this->identifier}_{$key}.php"))
			{
				// Cache exists

				$cache = include("{$this->path}/mako_{$this->identifier}_{$key}.php");

				if(time() < $cache['lifetime'])
				{
					// Cache has not expired ... fetch it

					return unserialize(stripslashes($cache['data']));
				}
				else
				{
					// Cache has expired ... delete it

					unlink("{$this->path}/mako_{$this->identifier}_{$key}.php");

					return false;
				}
			}
			else
			{
				// Cache doesn't exist

				return false;
			}
		}

		/**
		* Delete a variable from the cache.
		*
		* @access  public
		* @param   string   Cache key
		* @return  boolean
		*/

		public function delete($key)
		{
			if(file_exists("{$this->path}/mako_{$this->identifier}_{$key}.php"))
			{
				return unlink("{$this->path}/mako_{$this->identifier}_{$key}.php");
			}

			return false;
		}

		/**
		* Clears the user cache.
		*
		* @access  public
		* @return  boolean
		*/

		public function clear()
		{
			$files = scandir($this->path);

			if($files !== false)
			{
				foreach($files as $file)
				{
					if(mb_substr($file, 0, 5) === 'mako_')
					{
						if(unlink("{$this->path}/{$file}") === false)
						{
							return false;
						}
					}
				}
			}

			return true;
		}
	}
}

/** -------------------- End of file --------------------**/<commit_msg>Fixed bug in file cache adapter<commit_after><?php

namespace mako\cache
{
	use \mako\cache\Exception as CacheException;
	
	/**
	* File based cache adapter.
	*
	* @author     <NAME>
	* @copyright  (c) 2008-2011 <NAME>
	* @license    http://www.makoframework.com/license
	*/

	class File extends \mako\cache\Adapter
	{
		//---------------------------------------------
		// Class variables
		//---------------------------------------------

		/**
		* Cache path.
		*/

		protected $path;

		//---------------------------------------------
		// Class constructor, destructor etc ...
		//---------------------------------------------

		/**
		* Constructor.
		*
		* @access  public
		* @param   array   Configuration
		*/

		public function __construct(array $config)
		{
			parent::__construct($config['identifier']);
			
			$this->path = $config['path'];

			if(file_exists($this->path) === false || is_readable($this->path) === false || is_writable($this->path) === false)
			{
				throw new CacheException(__CLASS__.': Cache directory is not writable.');
			}
		}

		//---------------------------------------------
		// Class methods
		//---------------------------------------------

		/**
		* Store variable in the cache.
		*
		* @access  public
		* @param   string   Cache key
		* @param   mixed    The variable to store
		* @param   int      (optional) Time to live
		* @return  boolean
		*/

		public function write($key, $value, $ttl = 0)
		{
			$ttl = (((int) $ttl === 0) ? 31556926 : (int) $ttl) + time();

			$data = "<?php defined('MAKO_APPLICATION') or die();return array('lifetime' => {$ttl}, 'data' => '".base64_encode(serialize($value))."');";

			return is_int(file_put_contents("{$this->path}/mako_{$this->identifier}_{$key}.php", $data, LOCK_EX));
		}

		/**
		* Fetch variable from the cache.
		*
		* @access  public
		* @param   string  Cache key
		* @return  mixed
		*/

		public function read($key)
		{
			if(file_exists("{$this->path}/mako_{$this->identifier}_{$key}.php"))
			{
				// Cache exists

				$cache = include("{$this->path}/mako_{$this->identifier}_{$key}.php");

				if(time() < $cache['lifetime'])
				{
					// Cache has not expired ... fetch it

					return unserialize(base64_decode($cache['data']));
				}
				else
				{
					// Cache has expired ... delete it

					unlink("{$this->path}/mako_{$this->identifier}_{$key}.php");

					return false;
				}
			}
			else
			{
				// Cache doesn't exist

				return false;
			}
		}

		/**
		* Delete a variable from the cache.
		*
		* @access  public
		* @param   string   Cache key
		* @return  boolean
		*/

		public function delete($key)
		{
			if(file_exists("{$this->path}/mako_{$this->identifier}_{$key}.php"))
			{
				return unlink("{$this->path}/mako_{$this->identifier}_{$key}.php");
			}

			return false;
		}

		/**
		* Clears the user cache.
		*
		* @access  public
		* @return  boolean
		*/

		public function clear()
		{
			$files = scandir($this->path);

			if($files !== false)
			{
				foreach($files as $file)
				{
					if(mb_substr($file, 0, 5) === 'mako_')
					{
						if(unlink("{$this->path}/{$file}") === false)
						{
							return false;
						}
					}
				}
			}

			return true;
		}
	}
}

/** -------------------- End of file --------------------**/
{'fraction_non_alphanumeric': 0.2605222734254992, 'fraction_numerical': 0.006758832565284178, 'mean_word_length': 1.8064655172413793, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1346100', 'n_tokens_mistral': 2567, 'n_tokens_neox': 2051, 'n_words': 431}