0

According to magento Devdocs for Varnish cleaning

If you have configure in env.php the --http-cache-hosts parameter magento can clean Varnish cache from admin like it clean its internal caches.

This is done as mentioned when:

  1. Maintaining a website.

For example, anything you do in the Admin in:

STORES > Settings > Configuration > GENERAL > General

STORES > Settings > Configuration > GENERAL > Currency Setup

STORES > Settings > Configuration > GENERAL > Store Email Addresses

When Magento detects such a change, a message displays informing you to refresh the cache. To do this, see Refresh the Magento cache.

  1. Maintaining a store (for example, adding or editing categories, prices, products, and promotional pricing rules). Varnish is purged automatically when you perform any of these tasks.

Again like Devdocs saying

My question is this as I don't understand exactly:

In section 2 in DevDocs they say that

Varnish is purged automatically when you perform any of these tasks.

So When you actually work in admin like editing a product and change its price or name or something like this how magento handle the auto Varnish clean?

It cleans whole varnish cache like when you hit is server terminal : service varnish restart

or it purges the specific product you just edited?

I haven't understood this function completely. If you someone could explain it better please with the files in magento core which are responsible for this.

I am asking this because we work in admin a lot, changing prices or attributes in products. And because we have a large catalog we don’t want every time we edit a product magento to clean whole varnish as this affect our speed

1 Answer 1

1

The Magento way

Magento well send HTTP PURGE calls to Varnish and attach X-Magento-Tags-Pattern and X-Pool rheades to the request. This allows Varnish to remove objects from the cache that match these tags and pools.

It is important that your VCL configuration has the necessary code to handle HTTP PURGE requests.

See https://www.varnish-software.com/developers/tutorials/configuring-varnish-magento/ for more information about the VCL and the commands to flush the cache.

If you clear the cache using this mechanism, you can monitor the cache invalidations by showing Varnish's ban list. Run the following command to this the ban list:

sudo varnishadm ban.list

You should see the ban expression that Magento added.

The Varnish way

Although it is best to clear the Varnish cache using Magento's cache invalidation mechanisms, there is also another way to empty the entire cache. It uses the varnishadm command.

Run the following command to empty the entire Varnish cache:

sudo varnishadm ban obj.status "!=" 0

This will only empty the Varnish cache. Other Magento-related caches will not be affected. That's why it might be a good idea to use Magento's built-in cache invalidation commands

4
  • Thank you for your answer. So if I understood write "The Magento way" only cleans the specific product you edited and not the entire Varnish cache, right?
    – G. G.
    Feb 3, 2022 at 9:03
  • That depends on the action. As described in varnish-software.com/developers/tutorials/… you can run bin/magento cache:flush to flush the entire Magento cache. Feb 3, 2022 at 12:14
  • Probably I didn’t explain well. I edited my question. Please check last lines.
    – G. G.
    Feb 3, 2022 at 12:39
  • No worries, Magento will update individual objects in the cache when edits take place. It leverages Varnish bans behind the scenes and uses the X-Magento-Tags-Pattern header to send specific patterns to Varnish that it should remove from the cache. So not every action results in a full cache purge. Most of the times Magento is clever enough to remove specific objects from the cache. Feb 3, 2022 at 14:34

Your Answer

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

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