<commit_before><?php

/**
 * This file contains functions that deal with getting and setting cache values.
 *
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * @version 1.1 beta 2
 *
 */

namespace ElkArte\sources\subs\CacheMethod;

/**
 * Alternative PHP Cache or APC / APCu
 */
class Apc extends Cache_Method_Abstract
{
	/**
	 * {@inheritdoc }
	 */
	public function init()
	{
		return function_exists('apc_store');
	}

	/**
	 * {@inheritdoc }
	 */
	public function put($key, $value, $ttl = 120)
	{
		// An extended key is needed to counteract a bug in APC.
		if ($value === null)
			apc_delete($key . 'elkarte');
		else
			apc_store($key . 'elkarte', $value, $ttl);
	}

	/**
	 * {@inheritdoc }
	 */
	public function get($key, $ttl = 120)
	{
		$success = false;
		$result = apc_fetch($key . 'elkarte', $success);

		$this->is_miss = !$success;

		return $result;
	}

	/**
	 * {@inheritdoc }
	 */
	public function clean($type = '')
	{
		// If passed a type, clear that type out
		if ($type === '' || $type === 'data')
		{
			apc_clear_cache('user');
			apc_clear_cache('system');
		}
		elseif ($type === 'user')
			apc_clear_cache('user');
	}

	/**
	 * {@inheritdoc }
	 */<commit_msg>apcu<commit_after><?php

/**
 * This file contains functions that deal with getting and setting cache values.
 *
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * @version 1.1 beta 2
 *
 */

namespace ElkArte\sources\subs\CacheMethod;

/**
 * Alternative PHP Cache or APC / APCu
 */
class Apc extends Cache_Method_Abstract
{
	/**
	 * This is prefixed to all cacahe entries so that different
	 * applications won't interfere with each other.
	 *
	 * @var string
	 */
	protected $namespace = 'elkarte';

	/**
	 * Whether to use the APCu functions or the original APC ones.
	 *
	 * @var string
	 */
	protected $apcu = false;

	/**
	 * {@inheritdoc }
	 */
	public function init()
	{
		$this->apcu = function_exists('apcu_store');
	}

	/**
	 * {@inheritdoc }
	 */
	public function put($key, $value, $ttl = 120)
	{
		$namespacedKey = $this->namespace . ':' . $key;
		// An extended key is needed to counteract a bug in APC.
		if ($this->apcu)
		{
			if ($value === null)
				apcu_delete($namespacedKey);
			else
				apcu_store($namespacedKey, $value, $ttl);
		}
		else
		{
			if ($value === null)
				apc_delete($namespacedKey);
			else
				apc_store($namespacedKey, $value, $ttl);
		}
	}

	/**
	 * {@inheritdoc }
	 */
	public function get($key, $ttl = 120)
	{
		$namespacedKey = $this->namespace . ':' . $key;
		$success = false;
		if ($this->apcu)
			$result = apcu_fetch($namespacedKey, $success);
		else
			$result = apc_fetch($namespacedKey, $success);
		$this->is_miss = !$success;

		return $result;
	}

	/**
	 * {@inheritdoc }
	 */
	public function clean($type = '')
	{
		// If passed a type, clear that type out
		if ($type === '' || $type === 'data')
		{
			apc_clear_cache('user');
			apc_clear_cache('system');
		}
		elseif ($type === 'user')
			apc_clear_cache('user');
		elseif ($this->apcu)
			apcu_clear_cache();
	}

	/**
	 * {@inheritdoc }
	 */
{'fraction_non_alphanumeric': 0.16588857765328355, 'fraction_numerical': 0.006224712107065048, 'mean_word_length': 3.0225281602002503, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3081958', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1127, 'n_words': 284}