cachingredisdoctrine-odmsymfony-cmfdoctrine-phpcr

PHPCR nodes and meta cache override


I am using Symfony CMF, PHPCR and SncRedisBundle. I want to add metadata and nodes caching for PHPCR to SncRedisBundle.

For testing purposes, I have modified the loadDoctrine function in the file Snc\RedisBundle\DependencyInjection\SncRedisExtension.php (see the comment "PHPCR metadata definition override" for the code that I have added, 1 line).

protected function loadDoctrine(array $config, ContainerBuilder $container)
{
    foreach ($config['doctrine'] as $name => $cache) {
        $client = new Reference(sprintf('snc_redis.%s_client', $cache['client']));
        foreach ($cache['entity_managers'] as $em) {
            $def = new Definition($container->getParameter('snc_redis.doctrine_cache.class'));
            $def->setScope(ContainerInterface::SCOPE_CONTAINER);
            $def->addMethodCall('setRedis', array($client));
            if ($cache['namespace']) {
                $def->addMethodCall('setNamespace', array($cache['namespace']));
            }
            $container->setDefinition(sprintf('doctrine.orm.%s_%s', $em, $name), $def);
        }
        foreach ($cache['document_managers'] as $dm) {
            $def = new Definition($container->getParameter('snc_redis.doctrine_cache.class'));
            $def->setScope(ContainerInterface::SCOPE_CONTAINER);
            $def->addMethodCall('setRedis', array($client));
            if ($cache['namespace']) {
                $def->addMethodCall('setNamespace', array($cache['namespace']));
            }
            $container->setDefinition(sprintf('doctrine.odm.mongodb.%s_%s', $dm, $name), $def);
            //PHPCR metadata definition override
            $container->setDefinition(sprintf('doctrine_phpcr.odm.%s_%s', $dm, $name), $def);
        }
    }
}

This works for overriding the metadata cache and I can see in the Redis database that the metadata entries get populated.

Now I want to override the nodes result cache but I can't seem to find a way to do that. I cannot find the service definition name to use for the override. Can anyone point me in the right direction for this?


Solution

  • I managed to override the meta and nodes cache by digging into the container and looking at the provided services. The code in Snc\RedisBundle\DependencyInjection\SncRedisExtension.php has been reverted and only the config.yml file had to be modified.

    SncRedis overrides Doctrine's cache provider and since I wanted to use the same provider, I only had to set the meta to doctrine.orm.default_metadata_cache and nodes to doctrine.orm.default_result_cache.

    After that all doctrine meta and nodes result cache was being populated to my Redis server. Full configuration below:

    doctrine_phpcr:
        session:
            backend:
                type: doctrinedbal
                connection: default
                caches:
                    meta: doctrine.orm.default_metadata_cache
                    nodes: doctrine.orm.default_result_cache
            workspace: default
            username: admin
            password: admin
        odm:
            auto_mapping: true
            auto_generate_proxy_classes: "%kernel.debug%"