Search code examples
phpsymfonydeploymentdoctrine-ormdoctrine

'Class Doctrine\Common\Cache\ArrayCache does not exist' when installing a symfony project


I'm trying to deploy a symfony project following the steps:

./composer.phar update
php bin/console cache:clear

I've also tried to install manually doctrine driver ArrayCache running:

./composer.phar require doctrine/cache

The results is always the same and I end up with the following error:

# ./composer.phar update --no-interaction
[...]
Script cache:clear returned with error code 255
!!
!!  In ContainerBuilder.php line 1089:
!!
!!    Class Doctrine\Common\Cache\ArrayCache does not exist
!!
!!
!!
Script @auto-scripts was called via post-update-cmd

I'm new with symfony and I'm not able to understand why this class is missing.

I'm using the following versions:

"symfony/framework-bundle": "5.1.*",
"doctrine/doctrine-bundle": "^2.2",

Thanks in advance for your help.


Solution

  • After some time, I found a better solution:

    composer require symfony/cache
    

    then in php:

    $config = new Configuration;
    $queryCache = new PhpFilesAdapter('doctrine_queries'); $config->setQueryCache($queryCache);    
    $resultCache = new PhpFilesAdapter('doctrine_results', 0, $settings['cache_dir']); $config->setResultCache($resultCache);
    $metaCache = new PhpFilesAdapter('doctrine_metadata', 0, $settings['cache_dir']); $config->setMetadataCache($metaCache);
    

    I can now upgrade doctrine to the latest version.

    This is somewhere along the line of another answer, but since the documentation is so poor (for non-Symfony user), adding a few lines of php can make all the difference! Hope this helps some people. If this is for some reason not the best solution, I'm eager to hear.

    For me the solution is to downgrade to doctrine 2.7.4.

    Google'd around and it is obvious that Doctrine does not have its documentation in order. I'll put on my todo-list to look for another (3rd party) cache solution to replace the ArrayCache. I should have done this earlier, since ArrayCache is not suitable for production. Just hope Doctrine updates its documentation soon!

    If I find an alternative, I'll post it here. Or perhaps someone else beats me to it, I hope so!