<commit_before><?

namespace Gotron;

/**
 * Caching class with additional key naming functionality
 *
 * @package Gotron
 */
class Cache extends \ActiveRecord\Cache {

    public static function get($key, $closure, $ttl = 0) {
        $real_key = static::get_key($key);
        return parent::get($real_key, $closure, $ttl);
	}

    public static function get_key($key) {
        if(!is_array($key)) {
            $key = array($key);
        }

        foreach($key as $piece) {
            if(is_object($piece)) {
                // check for the property 'cache_key' and the method 'cache_key()'
                if(property_exists($piece, 'cache_key')) {
                    $key_pieces[]= $piece->cache_key;
                }
                else if(method_exists($piece, 'cache_key')) {
                    $key_pieces[]= $piece->cache_key();
                }
                else {
                    // Just so that we can at least get something here
                    $key_pieces[]= get_class($piece);
                }
            }
            else {
                $key_pieces[]= $piece;
            }
        }

        return join("/", $key_pieces);
    }

}

?><commit_msg>Modifying caching to be able to pull the key out<commit_after><?

namespace Gotron;

/**
 * Caching class with additional key naming functionality
 *
 * @package Gotron
 */
class Cache extends \ActiveRecord\Cache {

    public static function get($key, $closure, $ttl = 0) {
        $real_key = static::get_key($key);
        return parent::get($real_key, $closure, $ttl);
	}

    public static function get_key($key) {
        return join("/", static::key_parts($key));
    }

    public static function md5_key($key) {
        return md5(static::get_key($key));
    }

    protected static function key_parts($key) {
        if(!is_array($key)) {
            $key = array($key);
        }

        foreach($key as $piece) {
            if(is_object($piece)) {
                // check for the property 'cache_key' and the method 'cache_key()'
                if(property_exists($piece, 'cache_key')) {
                    $key_pieces[]= $piece->cache_key;
                }
                else if(method_exists($piece, 'cache_key')) {
                    $key_pieces[]= $piece->cache_key();
                }
                else {
                    // Just so that we can at least get something here
                    $key_pieces[]= get_class($piece);
                }
            }
            else {
                $key_pieces[]= $piece;
            }
        }

        return $key_pieces;
    }

}

?>
{'fraction_non_alphanumeric': 0.12811660912926737, 'fraction_numerical': 0.0015343306482546988, 'mean_word_length': 1.6237424547283703, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2840640', 'n_tokens_mistral': 768, 'n_tokens_neox': 720, 'n_words': 175}