phoenix icon indicating copy to clipboard operation
phoenix copied to clipboard

add support for configuring a result cache for the dbal

Open lsmith77 opened this issue 12 years ago • 7 comments

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 ..

lsmith77 avatar Sep 10 '12 18:09 lsmith77

Is it still possible to address this?

gena01 avatar May 27 '14 19:05 gena01

I would be nice to have this functionality

oleg-andreyev avatar Jun 17 '15 10:06 oleg-andreyev

+1

githoober avatar Jan 14 '16 23:01 githoober

We welcome pull requests

kimhemsoe avatar Mar 29 '18 17:03 kimhemsoe

Hi, any news on this??

Thanks.

cmaldonadowilson avatar Apr 22 '20 20:04 cmaldonadowilson

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';

HellPat avatar Jun 04 '20 14:06 HellPat

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")]);
    }
}

TeLiXj avatar Apr 05 '22 02:04 TeLiXj

Implemented & merged with #1721 for v2.11

chr-hertel avatar Nov 11 '23 16:11 chr-hertel