Skip to content
Permalink
Browse files

Update loading of SecondLevelCache in DI

SecondLevelCache now can use Default driver.
  • Loading branch information...
krekos authored and f3l1x committed Sep 6, 2018
1 parent 6678991 commit e97632f262d396837b7654d385c14f4ffc16c5c5
Showing with 18 additions and 1 deletion.
  1. +18 −1 src/DI/OrmCacheExtension.php
@@ -11,6 +11,9 @@
use Doctrine\Common\Cache\RedisCache;
use Doctrine\Common\Cache\VoidCache;
use Doctrine\Common\Cache\XcacheCache;
use Doctrine\ORM\Cache\CacheConfiguration;
use Doctrine\ORM\Cache\DefaultCacheFactory;
use Doctrine\ORM\Cache\RegionsConfiguration;
use Doctrine\ORM\Configuration;
use Nette\DI\CompilerExtension;
use Nette\DI\ServiceDefinition;
@@ -131,7 +134,21 @@ public function loadSecondLevelCacheConfiguration(): void
$builder = $this->getContainerBuilder();
$configuration = $builder->getDefinitionByType(Configuration::class);
if ($config['secondLevelCache'] !== null) {
if ($config['secondLevelCache'] === null && $config['defaultDriver']) {
$regions = $builder->addDefinition($this->prefix('regions'))
->setFactory(RegionsConfiguration::class)
->setAutowired(false);
$cacheFactory = $builder->addDefinition($this->prefix('cacheFactory'))
->setFactory(DefaultCacheFactory::class)
->setArguments([$regions, $this->getDefaultDriverCache('secondLevelCache')])
->setAutowired(false);
$cacheConfiguration = $builder->addDefinition($this->prefix('cacheConfiguration'))
->setFactory(CacheConfiguration::class)
->addSetup('setCacheFactory', [$cacheFactory])
->setAutowired(false);
$configuration->addSetup('setSecondLevelCacheEnabled', [true]);
$configuration->addSetup('setSecondLevelCacheConfiguration', [$cacheConfiguration]);
} elseif ($config['secondLevelCache'] !== null) {
$configuration->addSetup('setSecondLevelCacheEnabled', [true]);
$configuration->addSetup('setSecondLevelCacheConfiguration', [$config['secondLevelCache']]);
}

0 comments on commit e97632f

Please sign in to comment.
You can’t perform that action at this time.