<commit_before><?php
/*
PHP Cache

Author: <NAME>
Url: http://denbeke.be
Date: June 2013
*/


/**
@brief Class for Caching data

This class caches data in a folder. You can check if a cache is still valid, read a cache and write to a cache.

Don't forget to disallow all acces of the cache folder with .htaccess, when caching important data.
*/
class Cache {

    
    private $directory;
    private $defaultTime = 500;
    
    
    /**
    Constructor
    
    @param cache directory
    */
    public function __construct($directory = './cache/') {
        $this->directory = $directory;
    }
    
    
    /**
    Check if the cache of the given query has already expired
    
    @param query
    @param time after expired
    @return bool expired
    */
    public function isNotExpired($query, $time = NULL) {
        if ( is_null($time) ) {
                $time = $this->defaultTime;
        }
        elseif ($time == 0) {
            return true;
        }
        elseif ($time == -1) {
            return false;
        }
        $fileName = $this->directory.$this->encrypt($query);
        $modified = filemtime($fileName);
        $now = time();
        if(($now - $modified)  <= $time) {
            return true;
        }
        else {
            return false;
        }
    }
      
    
    /**
    Check if there is a cached file for the given query
    
    @param query
    @return bool
    */
    public function cacheExists($query) {
        $fileName = $this->directory.$this->encrypt($query);
        return file_exists($fileName);
    }
    
    
    /**
    Read the cache file of the given query
    
    @param query
    @return string containing file content
    */
    public function readCache($query) {
        $fileName = $this->directory.$this->encrypt($query);
        if(!file_exists($fileName)) {
            throw new exception("File does not exists");
        }
        else {
            return file_get_contents($fileName);
        }
    }
    
    
    /**
    Write the result of the query to a cache file
    
    @param query
    @param result
    */
    public function writeCache($query, $result) {
        $fileName = $this->directory.$this->encrypt($query);<commit_msg>Changed extension of cache files<commit_after><?php
/*
PHP Cache

Author: <NAME>
Url: http://denbeke.be
Date: June 2013
*/


/**
@brief Class for Caching data

This class caches data in a folder. You can check if a cache is still valid, read a cache and write to a cache.

Don't forget to disallow all acces of the cache folder with .htaccess, when caching important data.
*/
class Cache {

    
    private $directory;
    private $defaultTime = 500;
    private $extension = '.cache';
    
    
    /**
    Constructor
    
    @param cache directory
    */
    public function __construct($directory = './cache/') {
        $this->directory = $directory;
    }
    
    
    /**
    Check if the cache of the given query has already expired
    
    @param query
    @param time after expired
    @return bool expired
    */
    public function isNotExpired($query, $time = NULL) {
        if ( is_null($time) ) {
                $time = $this->defaultTime;
        }
        elseif ($time == 0) {
            return true;
        }
        elseif ($time == -1) {
            return false;
        }
        $fileName = $this->directory . $this->encrypt($query) . $this->extension;
        $modified = filemtime($fileName);
        $now = time();
        if(($now - $modified)  <= $time) {
            return true;
        }
        else {
            return false;
        }
    }
      
    
    /**
    Check if there is a cached file for the given query
    
    @param query
    @return bool
    */
    public function cacheExists($query) {
        $fileName = $this->directory.$this->encrypt($query) . $this->extension;
        return file_exists($fileName);
    }
    
    
    /**
    Read the cache file of the given query
    
    @param query
    @return string containing file content
    */
    public function readCache($query) {
        $fileName = $this->directory.$this->encrypt($query) . $this->extension;
        if(!file_exists($fileName)) {
            throw new exception("File does not exists");
        }
        else {
            return file_get_contents($fileName);
        }
    }
    
    
    /**
    Write the result of the query to a cache file
    
    @param query
    @param result
    */
    public function writeCache($query, $result) {
        $fileName = $this->directory.$this->encrypt($query) . $this->extension;
{'fraction_non_alphanumeric': 0.11179039301310044, 'fraction_numerical': 0.003930131004366812, 'mean_word_length': 1.8488805970149254, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '2678984', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1292, 'n_words': 405}