Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend dbal config and extension for result cache #1721

Merged
merged 4 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
chr-hertel marked this conversation as resolved.
Show resolved Hide resolved
->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: ~