<commit_before><commit_msg>added a simple static page cache<commit_after><?php

namespace Core;

class Cache {
    public function __construct($route=False) {
        if(file_exists($this->get_path()) && !DEBUG) {
            die(file_get_contents($this->get_path()));
        }
        else {
            ob_start();
            $this->dynamic = True;
        }
    }

    public function __destruct() {
        if($this->dynamic) {
            $handle = fopen($this->get_path(), 'w');
            fwrite($handle, ob_get_contents());
            fclose($handle);
            echo "GENERATED";
        }
    }

    private function get_path() {
        if(!is_dir(CACHE_PATH)) {
            throw new CacheError('Cache dir does not exist.');
        }
        return CACHE_PATH . '/' . md5($route);
    }
}

class CacheError extends Error {
    
}
?>
{'fraction_non_alphanumeric': 0.14, 'fraction_numerical': 0.001176470588235294, 'mean_word_length': 1.9755244755244756, 'pattern_counts': {'":': 0, '<': 4, '<?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': '4351304', 'n_tokens_mistral': 250, 'n_tokens_neox': 248, 'n_words': 50}