Home > database >  Is there a way to clear the cache automatically on Symfony?
Is there a way to clear the cache automatically on Symfony?

Time:09-24

I'm working on a "legacy" Symfony (it's using Symfony 4 but It's not maintained anymore). The problem is that the cache folder is growing every day, raising 50GB after a few months.

It's running as a DEV environment, but as the original developer left the company we would like to just "patch" the problem cleaning the cache after X time instead of changing the environment to a production one (which could lead to different problems and maybe it won't solve the cache issue), just like rotating Symfony logs where you can configure Symfony to log every day in a different file and remove old files automatically.

CodePudding user response:

There is no ready made way to do this from within the application.

Just clear the cache every now and then. (bin/console cache:clear). You could even schedule this as a cron job to run overnight, the process usually takes only a couple/few seconds at most.

Make sure that you run the command with the same user that's running the application (e.g. www-data, because if you run the command as root the cache will be warmed up with the wrong permissions).

Mind you, running a production system in development mode is inherently dangerous, as it's more likely to leak configuration data on unexpected situations.

  • Related