Symfony2 - How to set APC Doctrine cache prefix with multiple applications

Update: see the bottom of the post (this was published when we used SF 2.3, now we are at 2.7.0)

We have several Symfony applications running on our server, but we seem to get cache pollution on all sites due to all ORM cache entries of the doctrine with the prefix "sf2".

Distracted in the last 30 minutes, you will find that this is not an easy solution.

The first ones suggested using ProjectConfiguration.class.php - but that seems to be something like Symfony 1.

The next possible solution was to use the ApcUniversalClassLoader class (according to this question on SO: Multiple Symfony2 Sites using the APC cache ).

The problem is that our installation uses the composer for autoload, so we cannot just use the code in accordance with this example.

The APC caching class is excellent, you can set the key in the front controller, but it does not set the key for the doctrine cache.

Does anyone have any thoughts since we currently need to disable APC for the doctrine on all but the first application.

FrontController:

<?php

use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;

require_once __DIR__.'/../app/bootstrap.php.cache';

// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key    conflicts
// with other applications also using APC.
$loader = new ApcClassLoader('app_1', $loader);
$loader->register(true);

require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();

// wrap the default AppKernel with the AppCache one
require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppCache($kernel);

Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

- Refine - To clarify, the above code refers to the APC cache for classes, this works as described above and in order. what we cannot change are the default namespaces for the ORM APC doctrine entries, they seem to be fixed and thus run into each running instance.

- Update -

Zerrvox , , , . , , , , , , .

appProdProjectContainer .

protected function getDoctrineCache_Providers_Doctrine_Orm_DefaultMetadataCacheService()
{
....        
$instance->setNamespace('sf2orm_default_9e755ef08ba52b507455ecd06d0a648985c9593b15aca1522b4725acaaf77ce6');
        return $instance;
}

// Same for...

protected function getDoctrineCache_Providers_Doctrine_Orm_DefaultQueryCacheService   

protected function getDoctrineCache_Providers_Doctrine_Orm_DefaultResultCacheService
+4
2

, ORM- , Doctrine.

APC, , Symfony, (yml)

   app.doctrine.apc_cache:
       class: Doctrine\Common\Cache\ApcCache
       calls:
           - [setNamespace, ["app_namespace"]]

- -

. . Doctrine http://symfony.com/doc/current/reference/configuration/doctrine.html#caching-drivers

   doctrine:
       orm:
           metadata_cache_driver:
               type: service
               id: app.doctrine.apc_cache
+3

(Symfony 2.8 - 3.4):

doctrine_cache:
    providers:
        my_redis:
            type: redis
            namespace: "%prefix%"
            aliases:
              - redis_cache

"namespace" - , parameters.yml

0

All Articles