<commit_before><?php

/**
 * The purpose of this helper is to provide access to the cache server.
 */

namespace Helpers;

use App\Config;

class Cache
{
    private static $instance = null;
    private static $prefix = '';

    private function __construct() {}
    private function __clone() {}

    /**
     * @desc Get instance for Memcached.
     * @return null|object
     */
    private static function getInstance()
    {
        if (static::$instance === null) {
            $config  = Config::getByName('Cache');
            self::$prefix = $config['prefix'];

            static::$instance = new \Memcached();
            static::$instance->addServer($config['host'], $config['port']);
            if (static::$instance->getStats() === false) {
                Log::alert('memcache', 'No connection to the server is lost. Host: '.$config['host'].', Post: '.$config['port']);
            }
        }

        return static::$instance;
    }

    /**
     * @desc Set data into the cache.
     * @param string $key
     * @param string $value
     * @param integer $expiration
     */
    public static function set($key, $value, $expiration)
    {
        self::getInstance()->set(self::$prefix.$key, $value, $expiration);
    }

    /**
     * @desc Get data from the cache.
     * @param string $key
     * @return string
     */
    public static function get($key)
    {
        return self::getInstance()->get(self::$prefix.$key);
    }

    /**
     * @desc Return prefix
     * @return string
     */
    public static function getPrefix()
    {
        self::getInstance();

        return self::$prefix;
    }

    /**
     * @desc Delete data from the cache.
     * @param string $key
     */
    public static function delete($key)
    {
        self::getInstance()->delete(self::$prefix.$key);
    }

    /**
     * @desc Delete multiple items from the cache.
     * @param array $keys
     * @param integer $time
     */
    public static function deleteMulti($keys, $time = 0)
    {
        $prefix = self::$prefix;
        $keys = array_map(function($val) use ($prefix) { return $prefix.$val; }, $keys);

        self::getInstance()->deleteMulti($keys, $time);
    }

    /**
     * @desc Change the expiration time of a variables.
     * @param string $key
     * @param integer $expiration
     */
    public static function touch($key, $expiration)
    {
        self::getInstance()->touch(self::$prefix.$key, $expiration);
    }
}<commit_msg>Fix the extraction of cache prefix.<commit_after><?php

/**
 * The purpose of this helper is to provide access to the cache server.
 */

namespace Helpers;

use App\Config;

class Cache
{
    private static $instance = null;
    private static $prefix = '';

    private function __construct() {}
    private function __clone() {}

    /**
     * @desc Get instance for Memcached.
     * @return null|object
     */
    private static function getInstance()
    {
        if (static::$instance === null) {
            $config  = Config::getByName('Cache');
            self::$prefix = $config['prefix'];

            static::$instance = new \Memcached();
            static::$instance->addServer($config['host'], $config['port']);
            if (static::$instance->getStats() === false) {
                Log::alert('memcache', 'No connection to the server is lost. Host: '.$config['host'].', Post: '.$config['port']);
            }
        }

        return static::$instance;
    }

    /**
     * @desc Set data into the cache.
     * @param string $key
     * @param string $value
     * @param integer $expiration
     */
    public static function set($key, $value, $expiration)
    {
        self::getInstance()->set(self::$prefix.$key, $value, $expiration);
    }

    /**
     * @desc Get data from the cache.
     * @param string $key
     * @return string
     */
    public static function get($key)
    {
        return self::getInstance()->get(self::$prefix.$key);
    }

    /**
     * @desc Return prefix
     * @return string
     */
    public static function getPrefix()
    {
        self::getInstance();

        return self::$prefix;
    }

    /**
     * @desc Delete data from the cache.
     * @param string $key
     */
    public static function delete($key)
    {
        self::getInstance()->delete(self::$prefix.$key);
    }

    /**
     * @desc Delete multiple items from the cache.
     * @param array $keys
     * @param integer $time
     */
    public static function deleteMulti($keys, $time = 0)
    {
        $prefix = self::getPrefix();
        $keys = array_map(function($val) use ($prefix) { return $prefix.$val; }, $keys);

        self::getInstance()->deleteMulti($keys, $time);
    }

    /**
     * @desc Change the expiration time of a variables.
     * @param string $key
     * @param integer $expiration
     */
    public static function touch($key, $expiration)
    {
        self::getInstance()->touch(self::$prefix.$key, $expiration);
    }
}
{'fraction_non_alphanumeric': 0.15136876006441224, 'fraction_numerical': 0.00040257648953301127, 'mean_word_length': 2.2413568166992826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '7083520', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1382, 'n_words': 387}