Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony and Doctrine Metadata Cache

I am trying to optimize my Symfony application performances and I followed these posts:

  • https://symfony.com/doc/2.8/performance.html
  • Symfony2 Slow Initialization Time

I am "worried" about these lines:

doctrine:
    orm:
        entity_managers:
            default:
                metadata_cache_driver: apc
                query_cache_driver: apc
                result_cache_driver: apc

Are they safe to use or I must handle them with care after deploy? I am clearing the cache with php app/console cache:clear --env=prod --no-debug, do I need to clear APC cache too?

like image 570
StockBreak Avatar asked Nov 27 '17 09:11

StockBreak


1 Answers

Yes, in general, you should clear your APC cache after deployment. But it depends on what you've changed since your last deployment.

cache:clear won't clear the Doctrine cache. It only clears your cache directory (var/cache/{env} for Symfony 3+, app/cache for 2.8): FrameworkBundle/Command/CacheClearCommand.php

So you should clear the cache after deployment if something (for example your entities) has changed since the last deployment.

If you deploy manually, run these commands if applicable:

bin/console doctrine:cache:clear-query --env=prod
bin/console doctrine:cache:clear-result --env=prod
bin/console doctrine:cache:clear-metadata --env=prod

If you prefer better safe than sorry or if you deployment automatically, run all of them.

Unfortunately, the APC cache can't be clear using CLI. See this answer or this question. As an alternative, you can restart your webserver.

like image 67
Stephan Vierkant Avatar answered Oct 01 '22 04:10

Stephan Vierkant