Skip to content

Commit

Permalink
Update loading of SecondLevelCache in DI
Browse files Browse the repository at this point in the history
SecondLevelCache now can use Default driver.
  • Loading branch information
krekos authored and Milan Felix Šulc committed Sep 24, 2018
1 parent 6678991 commit e97632f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/DI/OrmCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']]);
}
Expand Down

0 comments on commit e97632f

Please sign in to comment.