diff options
-rw-r--r-- | config/environment/ui-test.php | 25 | ||||
-rw-r--r-- | config/global.php | 2 | ||||
-rw-r--r-- | core/Twig.php | 4 |
3 files changed, 29 insertions, 2 deletions
diff --git a/config/environment/ui-test.php b/config/environment/ui-test.php index 49126b20b6..9373ffb8b4 100644 --- a/config/environment/ui-test.php +++ b/config/environment/ui-test.php @@ -10,6 +10,31 @@ return array( 'tests.ui.url_normalizer_blacklist.api' => array(), 'tests.ui.url_normalizer_blacklist.controller' => array(), + 'twig.cache' => function (\Psr\Container\ContainerInterface $container) { + $templatesPath = $container->get('path.tmp.templates'); + return new class($templatesPath) extends \Twig\Cache\FilesystemCache { + public function write(string $key, string $content): void + { + $retryCount = 3; + + $attempts = 0; + while ($attempts < $retryCount) { + try { + parent::write($key, $content); + return; + } catch (\Exception $ex) { + if (!preg_match('/^Failed to write cache file/', $ex->getMessage())) { + throw $ex; + } + + usleep(50); + ++$attempts; + } + } + } + }; + }, + 'Piwik\Config' => \DI\decorate(function (\Piwik\Config $config) { $config->General['cors_domains'][] = '*'; $config->General['trusted_hosts'][] = '127.0.0.1'; diff --git a/config/global.php b/config/global.php index 1e43a2e479..d93adad66f 100644 --- a/config/global.php +++ b/config/global.php @@ -35,6 +35,8 @@ return array( 'view.clearcompiledtemplates.enable' => true, + 'twig.cache' => DI\string('path.tmp.templates'), + 'Matomo\Cache\Eager' => function (ContainerInterface $c) { $backend = $c->get('Matomo\Cache\Backend'); $cacheId = $c->get('cache.eager.cache_id'); diff --git a/core/Twig.php b/core/Twig.php index abf3549af2..5bbf10eaaa 100644 --- a/core/Twig.php +++ b/core/Twig.php @@ -134,13 +134,13 @@ class Twig $chainLoader = new ChainLoader($loaders); // Create new Twig Environment and set cache dir - $templatesCompiledPath = StaticContainer::get('path.tmp.templates'); + $cache = StaticContainer::get('twig.cache'); $this->twig = new Environment($chainLoader, array( 'debug' => true, // to use {{ dump(var) }} in twig templates 'strict_variables' => true, // throw an exception if variables are invalid - 'cache' => $templatesCompiledPath, + 'cache' => $cache, ) ); $this->twig->addExtension(new DebugExtension()); |