Skip to content

Commit

Permalink
Revert "Add PhpArrayAdapter to cache metadata"
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky authored Nov 10, 2020
1 parent 2aacd83 commit 386225f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 119 deletions.
35 changes: 0 additions & 35 deletions CacheWarmer/DoctrineMetadataCacheWarmer.php

This file was deleted.

7 changes: 0 additions & 7 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,13 +688,6 @@ private function getOrmCacheDriverNode(string $name): ArrayNodeDefinition
->scalarNode('pool')->end()
->end();

if ($name === 'metadata_cache_driver') {
$node->setDeprecated(...$this->getDeprecationMsg(
'The "metadata_cache_driver" configuration key is deprecated. PHP Array cache is now automatically registered when %kernel.debug% is false.',
'2.2'
));
}

return $node;
}

Expand Down
30 changes: 0 additions & 30 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection;

use Doctrine\Bundle\DoctrineBundle\CacheWarmer\DoctrineMetadataCacheWarmer;
use Doctrine\Bundle\DoctrineBundle\Dbal\ManagerRegistryAwareConnectionProvider;
use Doctrine\Bundle\DoctrineBundle\Dbal\RegexSchemaAssetFilter;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass;
Expand All @@ -22,8 +21,6 @@
use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber;
use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
Expand Down Expand Up @@ -816,12 +813,6 @@ protected function loadOrmCacheDrivers(array $entityManager, ContainerBuilder $c
$this->loadCacheDriver('metadata_cache', $entityManager['name'], $entityManager['metadata_cache_driver'], $container);
$this->loadCacheDriver('result_cache', $entityManager['name'], $entityManager['result_cache_driver'], $container);
$this->loadCacheDriver('query_cache', $entityManager['name'], $entityManager['query_cache_driver'], $container);

if ($container->getParameter('kernel.debug')) {
return;
}

$this->registerMetadataPhpArrayCaching($entityManager['name'], $container);
}

/**
Expand Down Expand Up @@ -935,25 +926,4 @@ private function createArrayAdapterCachePool(ContainerBuilder $container, string

return $id;
}

private function registerMetadataPhpArrayCaching(string $entityManagerName, ContainerBuilder $container): void
{
$metadataCacheAlias = $this->getObjectManagerElementName($entityManagerName . '_metadata_cache');
$decoratedMetadataCacheServiceId = (string) $container->getAlias($metadataCacheAlias);
$phpArrayCacheDecoratorServiceId = $decoratedMetadataCacheServiceId . '.php_array';
$phpArrayFile = '%kernel.cache_dir%' . sprintf('/doctrine/orm/%s_metadata.php', $entityManagerName);

$container->register(DoctrineMetadataCacheWarmer::class)
->setArguments([new Reference(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName)), $phpArrayFile])
->addTag('kernel.cache_warmer');

$container->setAlias($metadataCacheAlias, $phpArrayCacheDecoratorServiceId);
$container->register($phpArrayCacheDecoratorServiceId, DoctrineProvider::class)
->addArgument(
new Definition(PhpArrayAdapter::class, [
$phpArrayFile,
new Definition(DoctrineAdapter::class, [new Reference($decoratedMetadataCacheServiceId)]),
])
);
}
}
62 changes: 16 additions & 46 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider;
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -349,18 +347,6 @@ public function testDependencyInjectionConfigurationDefaults(): void
$definition = $container->getDefinition((string) $container->getAlias('doctrine.orm.default_metadata_cache'));
$this->assertEquals(DoctrineProvider::class, $definition->getClass());
$arguments = $definition->getArguments();
$this->assertInstanceOf(Definition::class, $arguments[0]);
$this->assertEquals(PhpArrayAdapter::class, $arguments[0]->getClass());
$arguments = $arguments[0]->getArguments();
$this->assertSame('%kernel.cache_dir%/doctrine/orm/default_metadata.php', $arguments[0]);
$this->assertInstanceOf(Definition::class, $arguments[1]);
$this->assertEquals(DoctrineAdapter::class, $arguments[1]->getClass());
$arguments = $arguments[1]->getArguments();
$this->assertInstanceOf(Reference::class, $arguments[0]);
$this->assertEquals('doctrine.orm.cache.provider.cache.doctrine.orm.default.metadata', (string) $arguments[0]);
$definition = $container->getDefinition((string) $arguments[0]);
$this->assertEquals(DoctrineProvider::class, $definition->getClass());
$arguments = $definition->getArguments();
$this->assertInstanceOf(Reference::class, $arguments[0]);
$this->assertEquals('cache.doctrine.orm.default.metadata', (string) $arguments[0]);
$this->assertSame(ArrayAdapter::class, $container->getDefinition((string) $arguments[0])->getClass());
Expand Down Expand Up @@ -766,9 +752,6 @@ public function testMessengerIntegration(): void
}
}

/**
* @group legacy
*/
public function testInvalidCacheConfiguration(): void
{
if (! interface_exists(EntityManagerInterface::class)) {
Expand Down Expand Up @@ -815,42 +798,15 @@ public function testCacheConfiguration(string $expectedAliasName, string $expect
$this->assertEquals($expectedAliasTarget, (string) $alias);
}

/**
* @dataProvider legacyCacheConfigurationProvider
* @group legacy
*/
public function testLegacyCacheConfiguration(string $expectedAliasName, string $expectedAliasTarget, string $cacheName, array $cacheConfig): void
{
$this->testCacheConfiguration($expectedAliasName, $expectedAliasTarget, $cacheName, $cacheConfig);
}

public static function legacyCacheConfigurationProvider(): array
public static function cacheConfigurationProvider(): array
{
return [
'metadata_cache_default' => [
'expectedAliasName' => 'doctrine.orm.default_metadata_cache',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.cache.doctrine.orm.default.metadata.php_array',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.cache.doctrine.orm.default.metadata',
'cacheName' => 'metadata_cache_driver',
'cacheConfig' => ['type' => null],
],
'metadata_cache_pool' => [
'expectedAliasName' => 'doctrine.orm.default_metadata_cache',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.metadata_cache_pool.php_array',
'cacheName' => 'metadata_cache_driver',
'cacheConfig' => ['type' => 'pool', 'pool' => 'metadata_cache_pool'],
],
'metadata_cache_service' => [
'expectedAliasName' => 'doctrine.orm.default_metadata_cache',
'expectedAliasTarget' => 'service_target_metadata.php_array',
'cacheName' => 'metadata_cache_driver',
'cacheConfig' => ['type' => 'service', 'id' => 'service_target_metadata'],
],
];
}

public static function cacheConfigurationProvider(): array
{
return [
'query_cache_default' => [
'expectedAliasName' => 'doctrine.orm.default_query_cache',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.cache.doctrine.orm.default.query',
Expand All @@ -863,6 +819,13 @@ public static function cacheConfigurationProvider(): array
'cacheName' => 'result_cache_driver',
'cacheConfig' => ['type' => null],
],

'metadata_cache_pool' => [
'expectedAliasName' => 'doctrine.orm.default_metadata_cache',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.metadata_cache_pool',
'cacheName' => 'metadata_cache_driver',
'cacheConfig' => ['type' => 'pool', 'pool' => 'metadata_cache_pool'],
],
'query_cache_pool' => [
'expectedAliasName' => 'doctrine.orm.default_query_cache',
'expectedAliasTarget' => 'doctrine.orm.cache.provider.query_cache_pool',
Expand All @@ -875,6 +838,13 @@ public static function cacheConfigurationProvider(): array
'cacheName' => 'result_cache_driver',
'cacheConfig' => ['type' => 'pool', 'pool' => 'result_cache_pool'],
],

'metadata_cache_service' => [
'expectedAliasName' => 'doctrine.orm.default_metadata_cache',
'expectedAliasTarget' => 'service_target_metadata',
'cacheName' => 'metadata_cache_driver',
'cacheConfig' => ['type' => 'service', 'id' => 'service_target_metadata'],
],
'query_cache_service' => [
'expectedAliasName' => 'doctrine.orm.default_query_cache',
'expectedAliasTarget' => 'service_target_query',
Expand Down
1 change: 0 additions & 1 deletion UPGRADE-2.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ Configuration
* `doctrine.dbal.keep_slave`. Use `doctrine.dbal.keep_replica`

Similarly, if you use XML configuration, please replace `<slave>` with `<replica>`.
* The `metadata_cache_driver` configuration key has been deprecated. PHP Array cache is now automatically registered when `%kernel.debug%` is false.

0 comments on commit 386225f

Please sign in to comment.