<commit_before><?php
/**
 * Memcache driver.
 * Implementation of http://www.smira.ru/2008/10/29/web-caching-memcached-5/
 * 
 * @package stalker_portal
 * @author <EMAIL>
 */

class Cache
{
    
    private $backend;
    private $use_custom_caching = false;
    
    private static $instance = NULL;

    /**
     * @static
     * @return Cache
     */
    public static function getInstance(){
        if (self::$instance == NULL)
        {
            self::$instance = new Cache();
        }
        return self::$instance;
    }
    
    private function __construct(){

        $this->backend = new Memcache;
        
        $this->backend->connect(Config::get('memcache_host'), 11211);
    }

    public function useCustomCaching($val){
        $this->use_custom_caching = !!$val;
    }

    private function customGet($key){

        $val = $this->backend->get($key);

        var_dump('-----------------------customGet', $key);

        if (!is_array($val)){
            return $val;
        }

        if(floatval($val['expire']) < time() && $val['expire'] != 0){
            $this->miss();
            return false;<commit_msg>Added error handling<commit_after><?php
/**
 * Memcache driver.
 * Implementation of http://www.smira.ru/2008/10/29/web-caching-memcached-5/
 * 
 * @package stalker_portal
 * @author <EMAIL>
 */

class Cache
{
    
    private $backend;
    private $use_custom_caching = false;
    
    private static $instance = NULL;

    /**
     * @static
     * @return Cache
     */
    public static function getInstance(){
        if (self::$instance == NULL)
        {
            self::$instance = new Cache();
        }
        return self::$instance;
    }
    
    private function __construct(){

        $this->backend = new Memcache;
        
        $status = $this->backend->connect(Config::get('memcache_host'), 11211);

        //var_dump($status);

        if (!$status){
            throw new Exception("Could not connect to memcached. Host: ".Config::get('memcache_host'));
        }
    }

    public function useCustomCaching($val){
        $this->use_custom_caching = !!$val;
    }

    private function customGet($key){

        $val = $this->backend->get($key);

        var_dump('-----------------------customGet', $key);

        if (!is_array($val)){
            return $val;
        }

        if(floatval($val['expire']) < time() && $val['expire'] != 0){
            $this->miss();
            return false;
{'fraction_non_alphanumeric': 0.1705237515225335, 'fraction_numerical': 0.012180267965895249, 'mean_word_length': 1.9758454106280192, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '2197913', 'n_tokens_mistral': 755, 'n_tokens_neox': 722, 'n_words': 148}