5

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

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?

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
StockBreak
  • 2,857
  • 1
  • 35
  • 61

1 Answers1

12

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.

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
  • I am using Symfony 2.8 and the cache directory is inside app, is it the same thing? I am using deployer for deploying my Symfony app but it doesn't seem to haandle Doctrine cache: https://github.com/deployphp/deployer/blob/master/recipe/symfony.php – StockBreak Nov 27 '17 at 13:26
  • Updated my answer. 'app/cache' was used before Symfony 3.0. I see deployer does not clear your Doctrine cache. See [this issue](https://github.com/deployphp/deployer/issues/444) for some background information. – Stephan Vierkant Nov 27 '17 at 13:31
  • Thanks! Last two questions: 1) do I need to specify the `--flush` parameter? 2) There is a comment in the post you linked: "If you use apc, you can't delete the cache using command", what does it mean? – StockBreak Nov 27 '17 at 13:37
  • I add another comment. In production I received this error: `Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI.` I noticed that in my deploy recipe I am already restarting PHP-FPM with `sudo /etc/init.d/php7.0-fpm restart`, is it already clearing APC cache? – StockBreak Nov 27 '17 at 13:52
  • You should execute `apc_clear_cache()`. See my updated answer. – Stephan Vierkant Nov 27 '17 at 14:19
  • What about FPM? If restarting FPM will suffice would you please add it to the solution so I can accept it? Thanks. – StockBreak Nov 27 '17 at 16:46
  • I added a link to an answer about restarting your webserver! – Stephan Vierkant Nov 28 '17 at 09:14
  • Where is this cache stored which is cleared by `doctrine:cache:clear-*` commands? – Roman Newaza Sep 23 '19 at 06:50