<commit_before><?php
namespace Gaia\ShortCircuit;
use Gaia\Cache;

/**
* allows us to cache the results of the resolver so we don't have to do expensive file I/O every
* time we need to resolve a URI to an action, or a view name to a template file.
*/
class CachedResolver implements Iface\Resolver
{
    /**
    * used when writing to the cache to store a missing value.
    */
    const UNDEF = '__UNDEF__';
    
   /**
    * cache object
    */
    protected $cache;
    
    /**
    * the resolver object we are wrapping. should i convert the resolver to an interface?
    */
    protected $core;
    
    /**
    * class constructor.
    */
    public function __construct( Iface\Resolver $resolver , Cache\IFace $cache){
        $this->cache = $cache;
        $this->core = $resolver;
    }

    /**
    * wrap the search method in a cache.
    */
    public function match( $uri,  & $args ){
        if( ! is_array( $args ) ) $args = array();
        $dir =  $this->core->appdir();
        $key = md5( __CLASS__ . '/' . __FUNCTION__ . '/' . $dir . '/' . $uri);
        $res = $this->cache->get( $key );
        if( $res == self::UNDEF ) return '';
        if( is_array( $res ) ) {
            if( is_array( $res['args'] ) ) $args = $res['args'];
            return $res['name'];
        }
        $name = $this->core->match( $uri, $args );<commit_msg>making shortcircuit compatible with storageiface<commit_after><?php
namespace Gaia\ShortCircuit;
use Gaia\StorageIface;

/**
* allows us to cache the results of the resolver so we don't have to do expensive file I/O every
* time we need to resolve a URI to an action, or a view name to a template file.
*/
class CachedResolver implements Iface\Resolver
{
    /**
    * used when writing to the cache to store a missing value.
    */
    const UNDEF = '__UNDEF__';
    
   /**
    * cache object
    */
    protected $cache;
    
    /**
    * the resolver object we are wrapping. should i convert the resolver to an interface?
    */
    protected $core;
    
    /**
    * class constructor.
    */
    public function __construct( Iface\Resolver $resolver , StorageIface $cache){
        $this->cache = $cache;
        $this->core = $resolver;
    }

    /**
    * wrap the search method in a cache.
    */
    public function match( $uri,  & $args ){
        if( ! is_array( $args ) ) $args = array();
        $dir =  $this->core->appdir();
        $key = md5( __CLASS__ . '/' . __FUNCTION__ . '/' . $dir . '/' . $uri);
        $res = $this->cache->get( $key );
        if( $res == self::UNDEF ) return '';
        if( is_array( $res ) ) {
            if( is_array( $res['args'] ) ) $args = $res['args'];
            return $res['name'];
        }
        $name = $this->core->match( $uri, $args );
{'fraction_non_alphanumeric': 0.14461761507792678, 'fraction_numerical': 0.0007249003262051468, 'mean_word_length': 2.1221719457013575, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '1070209', 'n_tokens_mistral': 865, 'n_tokens_neox': 858, 'n_words': 282}