Skip to content

Commit

Permalink
ConfigCache を使用するよう修正(EC-CUBE#1638)
Browse files Browse the repository at this point in the history
- see
  k-yamamura/eccube3-performance@58c8c86
- 単なる array ファイルをキャッシュにしているだけなので、Yaml に加えて
  array でも config ファイルを記述できるようにしたら良い気がします
  • Loading branch information
nanasess committed Aug 10, 2016
1 parent 8a70e61 commit 9680ad8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Eccube/Application.php
Expand Up @@ -27,6 +27,7 @@
use Eccube\Common\Constant;
use Eccube\EventListener\TransactionListener;
use Monolog\Logger;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -83,6 +84,13 @@ public function initConfig()
{
// load config
$this['config'] = $this->share(function() {
$cachePath = __DIR__.'/../../app/cache/'.Constant::CONFIG_CACHE_FILE_NAME;
$cache = new ConfigCache($cachePath, false);
if ($cache->isFresh()) {
error_log('cacheing');
return require $cachePath;
}

$ymlPath = __DIR__.'/../../app/config/eccube';
$distPath = __DIR__.'/../../src/Eccube/Resource/config';

Expand Down Expand Up @@ -158,7 +166,9 @@ public function initConfig()

$configAll = array_replace_recursive($configAll, $config_nav_dist, $config_nav);

return $configAll;
$resource = array();
$cache->write(sprintf('<?php return %s', var_export($configAll, true)).';', $resource);
return require $cachePath;
});
}

Expand Down
7 changes: 6 additions & 1 deletion src/Eccube/Common/Constant.php
Expand Up @@ -23,7 +23,8 @@

namespace Eccube\Common;

class Constant {
class Constant
{

/**
* EC-CUBE VERSION.
Expand All @@ -45,4 +46,8 @@ class Constant {
*/
const TOKEN_NAME = '_token';

/**
* Cache File Name.
*/
const CONFIG_CACHE_FILE_NAME = 'config.php.cache';
}

0 comments on commit 9680ad8

Please sign in to comment.