Skip to content

Commit d7f67f5

Browse files
authored
Extend dbal config and extension for result cache (#1721)
* 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
1 parent e168b42 commit d7f67f5

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
249249
->cannotBeEmpty()
250250
->defaultValue($this->getDefaultSchemaManagerFactory())
251251
->end()
252+
->scalarNode('result_cache')->end()
252253
->end();
253254

254255
// dbal < 2.11

DependencyInjection/DoctrineExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder
303303

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

306+
if (isset($connection['result_cache'])) {
307+
$configuration->addMethodCall('setResultCache', [new Reference($connection['result_cache'])]);
308+
}
309+
306310
if (class_exists(LegacySchemaManagerFactory::class)) {
307311
return;
308312
}

Resources/config/schema/doctrine-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<xsd:attribute name="profiling-collect-schema-errors" type="xsd:string" default="true" />
4040
<xsd:attribute name="server-version" type="xsd:string" />
4141
<xsd:attribute name="schema-manager-factory" type="xsd:string" />
42+
<xsd:attribute name="result-cache" type="xsd:string" />
4243
<xsd:attribute name="use-savepoints" type="xsd:boolean" />
4344
<xsd:attribute name="disable-type-comments" type="xsd:boolean" />
4445
<xsd:attributeGroup ref="driver-config" />

Resources/doc/configuration.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ Configuration Reference
142142
# collation: utf8mb4_unicode_ci # When using doctrine/dbal 3.x
143143
# engine: InnoDB
144144
145+
# Service identifier of a Psr\Cache\CacheItemPoolInterface implementation
146+
# to use as the cache driver for dbal result sets.
147+
result_cache: ~
148+
145149
replicas:
146150
# A collection of named replica connections (e.g. replica1, replica2)
147151
replica1:

Tests/DependencyInjection/AbstractDoctrineExtensionTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,26 @@ public function testDbalSchemaManagerFactory(): void
291291
);
292292
}
293293

294+
public function testDbalResultCache(): void
295+
{
296+
$container = $this->loadContainer('dbal_result_cache');
297+
298+
$this->assertDICDefinitionMethodCallOnce(
299+
$container->getDefinition('doctrine.dbal.connection_with_cache_connection.configuration'),
300+
'setResultCache',
301+
[
302+
new Reference('example.cache'),
303+
],
304+
);
305+
306+
$this->assertDICDefinitionMethodCallCount(
307+
$container->getDefinition('doctrine.dbal.connection_without_cache_connection.configuration'),
308+
'setResultCache',
309+
[],
310+
0,
311+
);
312+
}
313+
294314
public function testLoadSimpleSingleConnection(): void
295315
{
296316
if (! interface_exists(EntityManagerInterface::class)) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" ?>
2+
3+
<srv:container xmlns="http://symfony.com/schema/dic/doctrine"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:srv="http://symfony.com/schema/dic/services"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
8+
9+
<config>
10+
<dbal default-connection="connection_with_cache">
11+
<connection
12+
name="connection_with_cache"
13+
result-cache="example.cache" />
14+
<connection
15+
name="connection_without_cache" />
16+
</dbal>
17+
</config>
18+
</srv:container>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
doctrine:
2+
dbal:
3+
default_connection: connection_with_cache
4+
connections:
5+
connection_with_cache:
6+
result_cache: example.cache
7+
connection_without_cache: ~

0 commit comments

Comments
 (0)