简体   繁体   中英

How should I do to clean up the symfony2 cache

I'm a website administrator,my site were build on symfony2 freamwork. 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 :

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

the --env=prod tells the console to execute in the production environment. This will remove the previous cache.

Note:

By default Symfony will store session information in its cache directory. 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 .

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

The save_path setting will then store session information in 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. switch the public domain ip back to the production server.
  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. 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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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