Skip to content

Commit

Permalink
Extend dbal config and extension for result cache (#1721)
Browse files Browse the repository at this point in the history
* extend dbal config and extension for result cache
* extend configuration docs
* add result-cache to config schema xsd
* add config test for result cache option
  • Loading branch information
chr-hertel authored Nov 11, 2023
1 parent e168b42 commit d7f67f5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
->cannotBeEmpty()
->defaultValue($this->getDefaultSchemaManagerFactory())
->end()
->scalarNode('result_cache')->end()
->end();

// dbal < 2.11
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder

$configuration->addMethodCall('setSchemaManagerFactory', [new Reference($connection['schema_manager_factory'])]);

if (isset($connection['result_cache'])) {
$configuration->addMethodCall('setResultCache', [new Reference($connection['result_cache'])]);
}

if (class_exists(LegacySchemaManagerFactory::class)) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions Resources/config/schema/doctrine-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<xsd:attribute name="profiling-collect-schema-errors" type="xsd:string" default="true" />
<xsd:attribute name="server-version" type="xsd:string" />
<xsd:attribute name="schema-manager-factory" type="xsd:string" />
<xsd:attribute name="result-cache" type="xsd:string" />
<xsd:attribute name="use-savepoints" type="xsd:boolean" />
<xsd:attribute name="disable-type-comments" type="xsd:boolean" />
<xsd:attributeGroup ref="driver-config" />
Expand Down
4 changes: 4 additions & 0 deletions Resources/doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ Configuration Reference
# collation: utf8mb4_unicode_ci # When using doctrine/dbal 3.x
# engine: InnoDB
# Service identifier of a Psr\Cache\CacheItemPoolInterface implementation
# to use as the cache driver for dbal result sets.
result_cache: ~
replicas:
# A collection of named replica connections (e.g. replica1, replica2)
replica1:
Expand Down
20 changes: 20 additions & 0 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,26 @@ public function testDbalSchemaManagerFactory(): void
);
}

public function testDbalResultCache(): void
{
$container = $this->loadContainer('dbal_result_cache');

$this->assertDICDefinitionMethodCallOnce(
$container->getDefinition('doctrine.dbal.connection_with_cache_connection.configuration'),
'setResultCache',
[
new Reference('example.cache'),
],
);

$this->assertDICDefinitionMethodCallCount(
$container->getDefinition('doctrine.dbal.connection_without_cache_connection.configuration'),
'setResultCache',
[],
0,
);
}

public function testLoadSimpleSingleConnection(): void
{
if (! interface_exists(EntityManagerInterface::class)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" ?>

<srv:container xmlns="http://symfony.com/schema/dic/doctrine"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<config>
<dbal default-connection="connection_with_cache">
<connection
name="connection_with_cache"
result-cache="example.cache" />
<connection
name="connection_without_cache" />
</dbal>
</config>
</srv:container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
doctrine:
dbal:
default_connection: connection_with_cache
connections:
connection_with_cache:
result_cache: example.cache
connection_without_cache: ~

0 comments on commit d7f67f5

Please sign in to comment.