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

Viewed 6421

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.

4 Answers

I think you installed doctrine/cache 2.x version when installed "doctrine/doctrine-bundle": "^2.2",.

From github page:

This library is deprecated and will no longer receive bug fixes from the Doctrine Project. Please use a different cache library, preferably PSR-6 or PSR-16 instead.

So you have next options:

  • ./composer.phar require doctrine/cache:^1.11
  • To use other lib for cache for example symfony/cache

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!

I think it's established in the other answers that somewhere you are instantiating an instance of ArrayCache from the doctrine/cache package.

If you want equivalent functionality with doctrine/cache 2.x (where ArrayCache has been removed) you can do what doctrine/dbal itself will do.

I.e. instead of this...

$cache = new \Doctrine\Common\Cache\ArrayCache();

... you may instead do this (assuming you are comfortable introducing the symfony/cache package) ...

$cache = \Doctrine\Common\Cache\Psr6\DoctrineProvider::wrap(
    new \Symfony\Component\Cache\Adapter\ArrayAdapter()
)

This is what Doctrine itself does as a fallback when ArrayCache does not exists and you do not otherwise specify a cache in dev-mode. You can see the logic for how Doctrine decides to instantiate a cache at \Doctrine\ORM\Tools\Setup::createCacheInstance.

(Note: Even when you do not specify a cache, Doctrine will instantiate one automatically -- it could be storing values in Redis without you even realising )

To solve this problem, i first delete the composer.lock file, after, i installed composer with this following command: composer install and I installed the symfony cache dependency with this following command: composer require symfony/cach

->https://packagist.org/packages/symfony/cache

Related