diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index aba623dc..b8bce028 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -249,6 +249,7 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
->cannotBeEmpty()
->defaultValue($this->getDefaultSchemaManagerFactory())
->end()
+ ->scalarNode('result_cache')->end()
->end();
// dbal < 2.11
diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php
index 5633d451..6fc1d9fc 100644
--- a/DependencyInjection/DoctrineExtension.php
+++ b/DependencyInjection/DoctrineExtension.php
@@ -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;
}
diff --git a/Resources/config/schema/doctrine-1.0.xsd b/Resources/config/schema/doctrine-1.0.xsd
index 4a34eb34..3a9b7ab8 100644
--- a/Resources/config/schema/doctrine-1.0.xsd
+++ b/Resources/config/schema/doctrine-1.0.xsd
@@ -39,6 +39,7 @@
+
diff --git a/Resources/doc/configuration.rst b/Resources/doc/configuration.rst
index ad4ff7d8..ffe4c9ea 100644
--- a/Resources/doc/configuration.rst
+++ b/Resources/doc/configuration.rst
@@ -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:
diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
index 4e9be922..1e59ba11 100644
--- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
+++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
@@ -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)) {
diff --git a/Tests/DependencyInjection/Fixtures/config/xml/dbal_result_cache.xml b/Tests/DependencyInjection/Fixtures/config/xml/dbal_result_cache.xml
new file mode 100644
index 00000000..f2c9450a
--- /dev/null
+++ b/Tests/DependencyInjection/Fixtures/config/xml/dbal_result_cache.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Tests/DependencyInjection/Fixtures/config/yml/dbal_result_cache.yml b/Tests/DependencyInjection/Fixtures/config/yml/dbal_result_cache.yml
new file mode 100644
index 00000000..4a92be0a
--- /dev/null
+++ b/Tests/DependencyInjection/Fixtures/config/yml/dbal_result_cache.yml
@@ -0,0 +1,7 @@
+doctrine:
+ dbal:
+ default_connection: connection_with_cache
+ connections:
+ connection_with_cache:
+ result_cache: example.cache
+ connection_without_cache: ~