Graby\SiteConfig\ConfigBuilder::addToCache PHP Method

addToCache() public method

Add the given SiteConfig to the cache.
public addToCache ( string $key, SiteConfig $config )
$key string Key for the cache
$config SiteConfig Config to be cached
    public function addToCache($key, SiteConfig $config)
    {
        $key = strtolower($key);
        if (substr($key, 0, 4) == 'www.') {
            $key = substr($key, 4);
        }
        if ($config->cache_key) {
            $key = $config->cache_key;
        }
        $this->cache[$key] = $config;
        $this->logger->log('debug', 'Cached site config with key: {key}', array('key' => $key));
    }

Usage Example

Example #1
0
 public function testBuildWithCachedVersion()
 {
     $configBuilder = new ConfigBuilder(array('site_config' => array(dirname(__FILE__) . '/../fixtures/site_config')));
     $res = $configBuilder->build('fr.wikipedia.org');
     $this->assertInstanceOf('Graby\\SiteConfig\\SiteConfig', $res);
     $configBuilder->addToCache($res->cache_key, $res);
     $res2 = $configBuilder->build('fr.wikipedia.org');
     $this->assertInstanceOf('Graby\\SiteConfig\\SiteConfig', $res);
     $this->assertEquals($res, $res2, 'Config retrieve from cache');
 }