Symfony: Clear Doctrine Cache

Symfony: Clear doctrine cache

For Symfony 3+:

 php bin/console

will list all commands, the following are relevant for cache:

 php bin/console doctrine:cache:clear-metadata 
php bin/console doctrine:cache:clear-query
php bin/console doctrine:cache:clear-result

Before Symfony 3:

app/console

will list how you can do it

 app/console doctrine:cache:clear-metadata 
app/console doctrine:cache:clear-query
app/console doctrine:cache:clear-result

Symfony and Doctrine Metadata Cache

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.

Clear cache in Symfony: `cache:clear` or `rm -rf`?

cache:clear wipes previously created cache items, but also, it does a cache warm-up. Upon this, you application should load very fast due to the fact that cache was already pre-populated.

On the other hand, rm -rf does only one part of the job. You should notice performance impact when you try to load you app the first time after this.

I would also like to point out another thing: permissions. If you are logged in as root for example, and you did not set access rights via setfacl (or any other method), cache:clear will most probably create your cache items owned by root. This could be an issue, down the line.

Hope this helps a bit...

How to clear Doctrine APC cache for production?

You must understand that Php running under Apache (or Nginx) is different than the Php running via the command line, they are 2 Linux process that cant communicate.

So, even if you can clear the cache via CLI, this will not affect the php under Apache.

The easiest way it to call apcu_clear_cache inside a Symfony controller, or, you can use the Apache Php socket via the CLI.

I recommend to use a tool like http://gordalina.github.io/cachetool/, which do that perfectly.

Symfony & Doctrine - Repository or Doctrine cache to clear?

Sometimes that happend to me and the only thing I do is restart apache and whola. Is weird IDK why apache saves some cache for entities, try it and let me know if that works for you. Good Luck !



Related Topics



Leave a reply



Submit