Magento Internals: Cache Purging and Cache Tags

bin/magento cache:flush
php bin/magento setup:config:set --http-cache-hosts=<IP of varnish>
ESI tag used for megamenu.
  1. Varnish first requests home page from Magento
  2. Varnish looks for ESI tags in your page html.
  3. It find a ESI tag with url for rendering navigation menu.
  4. Varnish requests Megamenu by hitting /page_cache/block/esi/block/block_id` URL.
  5. Varnish composes received content with rest of the page and sends you the final response.
  6. Varnish stores Mengamenu separately from rest of the page.
x-magento-tags header
curl -X PURGE -H 'X-Magento-Tags-Pattern: cms_b_84' -H 'Host: example.com' <your varnish url>
curl -X PURGE -H 'X-Magento-Tags-Pattern: .*' -H 'Host: example.com' <your varnish url>
if (req.method == "PURGE") {
if (client.ip !~ purge) {
return (synth(405, "Method not allowed"));
}
# To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
# has been added to the response in your backend server config. This is used, for example, by the
# capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
}
if (req.http.X-Magento-Tags-Pattern) {
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
}
if (req.http.X-Pool) {
ban("obj.http.X-Pool ~ " + req.http.X-Pool);
}
return (synth(200, "Purged"));
}
if (req.http.X-Magento-Tags-Pattern) {
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
}
curl -I /page_cache/block/esi/blocks/%5B%22catalog.topnav%22%5D/handles/WyJkZWZhdWx0IiwiY21zX2luZGV4X2luZGV4IiwiY21zX3BhZ2VfdmlldyJd/
/**
* Return identifiers for produced content
*
* @return array
*/
public function getIdentities()
{
return [\Magento\Catalog\Model\Category::CACHE_TAG, \Magento\Store\Model\Group::CACHE_TAG];
}
if ($blockInstance instanceof \Magento\Framework\DataObject\IdentityInterface) {
$response->setHeader('X-Magento-Tags', implode(',', $blockInstance->getIdentities()));
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store