phoenix
phoenix copied to clipboard
add support for configuring a result cache for the dbal
i briefly looked into this, but the AbstractDoctrineExtension cache related code is pretty bound to just the ORM. not sure if to just duplicate code .. kinda too late for 2.1 of course ..
Is it still possible to address this?
I would be nice to have this functionality
+1
We welcome pull requests
Hi, any news on this??
Thanks.
I hacked around for my project, and this seems to work. I'm not experienced here, so take it at your own risk:
diff --git a/src/DependencyInjection/DBALResultCachePass.php b/src/DependencyInjection/DBALResultCachePass.php
new file mode 100644
index 000000000..724652385
--- /dev/null
+++ b/src/DependencyInjection/DBALResultCachePass.php
@@ -0,0 +1,20 @@
+<?php declare(strict_types=1);
+
+namespace App\DependencyInjection;
+
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Reference;
+
+final class DBALResultCachePass implements CompilerPassInterface
+{
+ /**
+ * @inheritdoc
+ */
+ public function process(ContainerBuilder $container): void
+ {
+ $connectionDefinition = $container->getDefinition('doctrine.dbal.connection.configuration');
+
+ $connectionDefinition->addMethodCall('setResultCacheImpl', [new Reference('doctrine.orm.default_result_cache')]);
+ }
+}
diff --git a/src/Kernel.php b/src/Kernel.php
index 789685300..8a203bef9 100644
--- a/src/Kernel.php
+++ b/src/Kernel.php
@@ -2,6 +2,7 @@
namespace App;
+use App\DependencyInjection\DBALResultCachePass;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
@@ -37,6 +38,8 @@ class Kernel extends BaseKernel
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
{
+ $container->addCompilerPass(new DBALResultCachePass());
+
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir() . '/config';
I use a very similar code only adding a line in the Kernel.php
, but in the last version setResultCacheImpl
is deprecated and now only works setResultCache
<?php
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
class Kernel extends BaseKernel implements CompilerPassInterface
{
use MicroKernelTrait;
public function process(ContainerBuilder $container)
{
$container
->getDefinition("doctrine.dbal.default_connection.configuration")
->addMethodCall("setResultCache", [new Reference("doctrine.orm.default_result_cache")]);
}
}
Implemented & merged with #1721 for v2.11