<commit_before><?php
/**
 * @title            Cache Class
 * @desc             Handler Cache.
 *
 * @author           <NAME> <<EMAIL>>
 * @copyright        (c) 2011-2018, <NAME>. All Rights Reserved.
 * @license          GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
 * @package          PH7 / Framework / Cache
 * @version          1.3
 */

namespace PH7\Framework\Cache;

defined('PH7') or exit('Restricted access');

use PH7\Framework\Config\Config;
use PH7\Framework\Core\Kernel;
use PH7\Framework\Error\CException\PH7InvalidArgumentException;
use PH7\Framework\File\File;

class Cache
{
    const DATETIME_FORMAT = 'Y-m-d H:i:s';
    const CACHE_DIR = 'pH7_cache/';
    const CACHE_FILE_EXT = '.cache.php';

    /** @var File */
    private $oFile;

    /** @var string */
    private $sCacheDir;

    /** @var string */
    private $sGroup;

    /** @var string */
    private $sId;

    /** @var int */
    private $iTtl;

    /** @var string */
    private $sPrefix = 'pH7_';

    /** @var bool */
    private $bEnabled = true;

    public function __construct()
    {
        $this->oFile = new File;
        $this->bEnabled = (bool)Config::getInstance()->values['cache']['enable.general.cache'];
    }

    /**
     * Enabled/Disabled the cache.
     *
     * @param bool $bIsEnable
     *
     * @return self
     */
    public function enabled($bIsEnable)
    {
        $this->bEnabled = (bool)$bIsEnable;

        return $this;
    }

    /**
     * Sets cache directory.
     * If the directory is not correct, the method will cause an exception.
     * If you do not use this method, a default directory will be created.
     *
     * @param string $sCacheDir
     *
     * @return self
     *
     * @throws PH7InvalidArgumentException An explanatory message if the directory does not exist.
     */
    public function setCacheDir($sCacheDir)
    {
        if (is_dir($sCacheDir)) {
            $this->sCacheDir = $sCacheDir;
        } else {
            throw new PH7InvalidArgumentException('"' . $sCacheDir . '" cache directory cannot be found!');
        }

        return $this;
    }

    /**
     * Sets the cache prefix.
     *
     * @param string $sPrefix
     *
     * @return self
     */
    public function setPrefix($sPrefix)
    {
        $this->sPrefix = $sPrefix;

        return $this;
    }

    /**
     * Start the cache.
     *
     * @param string $sGroup The Group Cache (This creates a folder).
     * @param string $sId (The ID for the file).
     * @param int $iTtl Cache lifetime in seconds. If NULL, the file never expires.
     *
     * @return self
     */
    public function start($sGroup, $sId, $iTtl)
    {
        $this->checkCacheDir();

        if ($this->bEnabled) {
            $this->sGroup = $sGroup . PH7_DS;
            $this->sId = $sId;
            $this->iTtl = (int)$iTtl;
            ob_start();
        }

        return $this;
    }

    /**
     * Stop the cache.
     *
     * @param bool $bPrint TRUE = Display data with ECHO. FALSE = Return data.
     *
     * @return string|null
     */
    public function stop($bPrint = true)
    {
        if (!$this->bEnabled) {
            return null;
        }

        $sBuffer = ob_get_contents();
        ob_end_clean();
        $this->write($sBuffer);

        if ($bPrint) {
            echo $sBuffer;
            return null;
        }

        return $sBuffer;
    }

    /**
     * Sets the time expire cache.
     *
     * @return self
     */
    public function setExpire()
    {
        // How long to cache for (in seconds, e.g. 3600*24 = 24 hour)
        @touch($this->getFile(), time() + $this->iTtl);
<commit_msg>Remove caching data pages with Output Buffering feature<commit_after><?php
/**
 * @title            Cache Class
 * @desc             Handler Cache.
 *
 * @author           <NAME> <<EMAIL>>
 * @copyright        (c) 2011-2018, <NAME>. All Rights Reserved.
 * @license          GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
 * @package          PH7 / Framework / Cache
 * @version          1.3
 */

namespace PH7\Framework\Cache;

defined('PH7') or exit('Restricted access');

use PH7\Framework\Config\Config;
use PH7\Framework\Core\Kernel;
use PH7\Framework\Error\CException\PH7InvalidArgumentException;
use PH7\Framework\File\File;

class Cache
{
    const DATETIME_FORMAT = 'Y-m-d H:i:s';
    const CACHE_DIR = 'pH7_cache/';
    const CACHE_FILE_EXT = '.cache.php';

    /** @var File */
    private $oFile;

    /** @var string */
    private $sCacheDir;

    /** @var string */
    private $sGroup;

    /** @var string */
    private $sId;

    /** @var int */
    private $iTtl;

    /** @var string */
    private $sPrefix = 'pH7_';

    /** @var bool */
    private $bEnabled = true;

    public function __construct()
    {
        $this->oFile = new File;
        $this->bEnabled = (bool)Config::getInstance()->values['cache']['enable.general.cache'];
    }

    /**
     * Enabled/Disabled the cache.
     *
     * @param bool $bIsEnable
     *
     * @return self
     */
    public function enabled($bIsEnable)
    {
        $this->bEnabled = (bool)$bIsEnable;

        return $this;
    }

    /**
     * Sets cache directory.
     * If the directory is not correct, the method will cause an exception.
     * If you do not use this method, a default directory will be created.
     *
     * @param string $sCacheDir
     *
     * @return self
     *
     * @throws PH7InvalidArgumentException An explanatory message if the directory does not exist.
     */
    public function setCacheDir($sCacheDir)
    {
        if (is_dir($sCacheDir)) {
            $this->sCacheDir = $sCacheDir;
        } else {
            throw new PH7InvalidArgumentException('"' . $sCacheDir . '" cache directory cannot be found!');
        }

        return $this;
    }

    /**
     * Sets the cache prefix.
     *
     * @param string $sPrefix
     *
     * @return self
     */
    public function setPrefix($sPrefix)
    {
        $this->sPrefix = $sPrefix;

        return $this;
    }

    /**
     * Start the cache.
     *
     * @param string $sGroup The Group Cache (This creates a folder).
     * @param string $sId (The ID for the file).
     * @param int $iTtl Cache lifetime in seconds. If NULL, the file never expires.
     *
     * @return self
     */
    public function start($sGroup, $sId, $iTtl)
    {
        $this->checkCacheDir();

        $this->sGroup = $sGroup . PH7_DS;
        $this->sId = $sId;
        $this->iTtl = (int)$iTtl;

        return $this;
    }

    /**
     * Sets the time expire cache.
     *
     * @return self
     */
    public function setExpire()
    {
        // How long to cache for (in seconds, e.g. 3600*24 = 24 hour)
        @touch($this->getFile(), time() + $this->iTtl);

{'fraction_non_alphanumeric': 0.12988338192419824, 'fraction_numerical': 0.009620991253644314, 'mean_word_length': 1.9121392190152802, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 38, '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': '2127978', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2100, 'n_words': 586}