Symfony framework provides many built-in console commands through the bin/console script to perform various tasks.
This tutorial provides 2 methods how to clear cache using console command in Symfony 7 application.
Method 1 - clear and warm up
The cache:clear command can be used to clear and warm up the application cache.
php bin/console cache:clear
The command will run in the environment defined by the APP_ENV environment variable in the .env file. By default, dev. We can use the --env or -e option to clear and warm up the cache for the specified environment.
php bin/console cache:clear --env=prod
Method 2 - clear and warm up later
The cache:clear command clears the cache and by default warms up the cache. The --no-warmup option can be used to disable warm up the cache.
We can warm up the cache later using cache:warmup command. Note that, the cache must be empty before running this command.
php bin/console cache:clear --no-warmup
php bin/console cache:warmup
Environment can be specified with --env or -e option.
php bin/console cache:clear --no-warmup --env=prod
php bin/console cache:warmup --env=prod
Leave a Comment
Cancel reply