简体   繁体   English

我应该如何清理symfony2缓存

[英]How should I do to clean up the symfony2 cache

I'm a website administrator,my site were build on symfony2 freamwork. 我是网站管理员,我的网站建立在symfony2框架上。 My site has a lot of users.When I clear the cache,a few users are accessing my website,so I can not quite put clean cache that caused a lot of problems. 我的网站上有很多用户。当我清除缓存时,有几个用户正在访问我的网站,因此我不能完全清除干净的缓存,这会引起很多问题。 How should I do to clean up the cache? 我应该如何清理缓存?

To clear the cache in symfony you need to execute the following command : 要清除symfony中的缓存,您需要执行以下命令:

php app/console cache:clear --env=prod

the --env=prod tells the console to execute in the production environment. --env=prod告诉console在生产环境中执行。 This will remove the previous cache. 这将删除先前的缓存。

Note: 注意:

By default Symfony will store session information in its cache directory. 默认情况下,Symfony将会话信息存储在其缓存目录中。 Clearing the cache will mean that every user has to re-authenticate. 清除缓存将意味着每个用户都必须重新进行身份验证。

You can change the path that Symfony uses to store the session files by changing the following line in the app/config/config.yml . 您可以通过更改app/config/config.yml的以下行来更改Symfony用于存储会话文件的路径。

framework:
    session:
        save_path: %kernel.root_dir%/sessions

The save_path setting will then store session information in app/sessions . 然后save_path设置将会话信息存储在app/sessions

I had faced this problem multiple times. 我已经多次面对这个问题。 If your website was accessing by so many user and you clear the cache. 如果您的网站被这么多用户访问,并且您清除了缓存。 i am sure your website was down for couple for minutes until the new cache generated. 我确定您的网站已经关闭了几分钟,直到生成新的缓存。

So clear cache on production server should not be a regular activity. 因此,在生产服务器上清除缓存不应该是常规活动。 There are couple of solution or tricks to overcome from this problem: 有两个解决方案或技巧可以解决此问题:

  1. find the time when your website has low traffic. 查找网站流量较低的时间。 May be sometime in the night and then clear the cache. 可能是晚上的某个时间,然后清除缓存。
  2. When you want to clear a cache, setup a replica of a production server then plan to switch the public domain ip to the new replica for the timing so that user cant face the downtime and once you cleared the cache on a actually production server. 当您要清除缓存时,请设置生产服务器的副本,然后计划将公用域ip切换到新副本以进行计时,以使用户无法面对停机时间,并且一旦您清除了实际生产服务器上的缓存即可。 switch the public domain ip back to the production server. 将公共域ip切换回生产服务器。
  3. if you do some changes in the templates ietwig and wants to made changes live on the production.Then try to find the templates in the app/cache/prod/twig directory and grep the templates name and you will get the files. 如果您对模板ietwig进行了一些更改并且想要在产品中进行更改,然后尝试在app / cache / prod / twig目录中找到模板并grep模板名称,您将获得文件。 Than move the files or delete the files and yours changes will live on the production server. 通过移动文件或删除文件,您所做的更改将保存在生产服务器上。

how to clear the cache 如何清除缓存

php app/console cache:clear 
chmod -R 777 app/cache
chmod -R 777 app/logs 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM