0

I have setup varnish and varnish is working okay with service varnish restart command but i want to restart varnish with php bin/magento cache:flush command.

Does anyone suggest me how i can do this .

1 Answer 1

1

As described on https://www.varnish-software.com/developers/tutorials/configuring-varnish-magento/#6-making-cache-purges-work, you should register the Varnish endpoints with Magento.

You can use the following command, assuming Varnish runs on localhost:

bin/magento setup:config:set --http-cache-hosts=localhost

Once Magento is aware of how to connect to Varnish, you can run the following command to flush the Varnish cache along with other Magento caches:

bin/magento cache:flush

Debugging cache invalidation in Varnish

If you want to debug the cache invalidation process in Varnish, you can run the following command:

sudo varnishadm ban.list

This command will print the list of bans that were issued by Varnish. this banning mechanism is leveraged by Magento to remove objects from the cache.

Here's some example output:

sudo varnishadm ban.list
Present bans:
1603272627.622051     0 -  obj.status != 0
1603270370.244746     3 C

The ban that is on the list was issued through the following ban expression:

obj.status != 0

Literally every HTTP status code of objects stored in the cache is not zero, so that expression would invalidate the entire cache.

In your case, the ban expression will be related to properties that were set by Magento.

2
  • i already tried it but not working Commented Feb 28, 2022 at 7:53
  • @SanjayShiyal the information you're providing is not really helpful. I did add a section to my answer about debugging the cache invalidation in Varnish. Maybe that can help. But if the ban doesn't end up on the ban list, you're stuck as well. My advice is to also have a look at the Magento logs. If there are log items related to cache invalidation, please share them here. Commented Feb 28, 2022 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.