[英]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/*
? ./bin/console cache:clear --env=prod
和rm -rf var/cache/prod/*
之间的区别是什么? Console command is very slow.控制台命令很慢。 Bash command is fast.
Bash 命令很快。 So, ... why use
cache:clear
instead of rm
?那么,...为什么使用
cache:clear
而不是rm
?
cache:clear
wipes previously created cache items, but also , it does a cache warm-up. cache:clear
湿巾以前创建的缓存项,而且,它确实缓存热身。 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.另一方面,
rm -rf
只完成工作的一部分。 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
.例如,如果您以
root
身份登录,并且没有通过setfacl
(或任何其他方法)设置访问权限,则cache:clear
很可能会创建root
拥有的缓存项。 This could be an issue, down the line.这可能是一个问题,下线。
Hope this helps a bit...希望这会有所帮助...
"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". "cache:clear" 命令不仅删除缓存,而且通常会构建更新的缓存数据(预热),这样 symfony 就不必在第一个请求到来后创建一个,这就是它比单纯的花费更多时间的原因通过“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 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.所以,通常最好运行cache:clear,至少在整个部署过程中是这样。 The occasion you would use rm command is usually only when some file permissions have gone wrong (ie maybe you had run a command with a wrong user ) and there were no choices left, I think.
我认为,您使用 rm 命令的情况通常是在某些文件权限出错时(即,您可能使用错误的用户运行了一个命令)并且没有其他选择。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.