<commit_before><?php

/*
 * This file is part of php-cache organization.
 *
 * (c) 2015-2015 <NAME> <<EMAIL>>, <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Cache\Adapter\Apcu;

use Cache\Adapter\Common\AbstractCachePool;
use Psr\Cache\CacheItemInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class ApcuCachePool extends AbstractCachePool
{
    /**
     * {@inheritdoc}
     */
    protected function fetchObjectFromCache($key)
    {
        $success = false;
        $data    = apcu_fetch($key, $success);

        return [$success, $data, []];
    }

    /**
     * {@inheritdoc}
     */
    protected function clearAllObjectsFromCache()
    {
        return apcu_clear_cache();
    }

    /**
     * {@inheritdoc}
     */
    protected function clearOneObjectFromCache($key)
    {
        apcu_delete($key);

        return true;
    }

    /**
     * {@inheritdoc}
     */
    protected function storeItemInCache(CacheItemInterface $item, $ttl)
    {
        if ($ttl < 0) {
            return false;
        }

        return apcu_store($item->getKey(), $item->get(), $ttl);
    }
}<commit_msg>Update ApcuCachePool.php<commit_after><?php

/*
 * This file is part of php-cache organization.
 *
 * (c) 2015-2015 <NAME> <<EMAIL>>, <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Cache\Adapter\Apcu;

use Cache\Adapter\Common\AbstractCachePool;
use Psr\Cache\CacheItemInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class ApcuCachePool extends AbstractCachePool
{
    /**
     * @var bool
     */
    private $skipOnCli;
    
    /**
     * @param bool $skipOnCli
     */
    public function __construct($skipOnCli = false)
    {
        $this->skipOnCli = $skipOnCli;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function fetchObjectFromCache($key)
    {
        if ($this->skipIfCli()) {
            return [false, null, []];
        }
        
        $success = false;
        $data    = apcu_fetch($key, $success);

        return [$success, $data, []];
    }

    /**
     * {@inheritdoc}
     */
    protected function clearAllObjectsFromCache()
    {
        return apcu_clear_cache();
    }

    /**
     * {@inheritdoc}
     */
    protected function clearOneObjectFromCache($key)
    {
        apcu_delete($key);

        return true;
    }

    /**
     * {@inheritdoc}
     */
    protected function storeItemInCache(CacheItemInterface $item, $ttl)
    {
        if ($this->skipIfCli()) {
            return false;
        }
        
        if ($ttl < 0) {
            return false;
        }

        return apcu_store($item->getKey(), $item->get(), $ttl);
    }
    
    /**
     * Returns true if CLI and if it should skip on cli
     * 
     * @return bool
     */
    private function skipIfCli()
    {
        return php_sapi_name() === 'cli' && $this->skipOnCli;
    }
}
{'fraction_non_alphanumeric': 0.13825191093386507, 'fraction_numerical': 0.005982053838484547, 'mean_word_length': 2.0558375634517767, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, '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': '3727278', 'n_tokens_mistral': 980, 'n_tokens_neox': 933, 'n_words': 217}