sensorario
sensorario

Reputation: 21620

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

Which is the difference between ./bin/console cache:clear --env=prod and rm -rf var/cache/prod/*? Console command is very slow. Bash command is fast. So, ... why use cache:clear instead of rm?

Upvotes: 45

Views: 136299

Answers (3)

Mostafa
Mostafa

Reputation: 1009

You better use the "official" best approach that it using cache:clear not using rm...follow the best practices and here almost all commands:

  cache:clear                             Clears the cache
  cache:pool:clear                        Clears cache pools
  cache:warmup                            Warms up an empty cache
  doctrine:cache:clear-collection-region  Clear a second-level cache collection region.
  doctrine:cache:clear-entity-region      Clear a second-level cache entity region.
  doctrine:cache:clear-metadata           Clears all metadata cache for an entity manager
  doctrine:cache:clear-query              Clears all query cache for an entity manager
  doctrine:cache:clear-query-region       Clear a second-level cache query region.
  doctrine:cache:clear-result             Clears result cache for an entity manager

Upvotes: 5

Motoroller
Motoroller

Reputation: 479

"cache:clear" command not only removes the cache but they usually build the updated cache data (warm up) so that symfony does not have to create one after the first request comes, which is the reason that it takes more time than the mere removal of files under your cache folder by "rm -rf". Even if you can finish that command faster, it would take time for you to process the first request, if you have not created cache in advance by this command.

http://symfony.com/doc/current/console/usage.html

So, usually it is better to run cache:clear, at least in the whole process of deployment. The occasion you would use rm command is usually only when some file permissions have gone wrong (i.e. maybe you had run a command with a wrong user ) and there were no choices left, I think.

Upvotes: 13

Jovan Perovic
Jovan Perovic

Reputation: 20191

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...

Upvotes: 59

Related Questions