Magento 2.2 – Restart Varnish After Clearing Cache to See Changes

cachemagento2.2varnish

I am new to optimizing and maintaining Magento 2.2. I have an installation that are setup with:

  • Dedicated server
  • Ubuntu 16.04
  • Nginx
  • PHP 7
  • MySQL 5.7
  • Magento 2.2
  • memcached
  • Redis
  • Varnish 4

I am confused about a couple of things regarding indexing, cache & varnish and I am sorry if my questions seems stupid/weird:

  1. It seems when I make some changes i have to clear the cache in the admin and restart Varnish (service nginx restart) from the shell for the changes to be shown in the front-end. Is it supposed to be like this or can I somehow link restart of varnish with clearing of cache? Or is there something I am missing?
  2. After restart of Varnish it seems there are a "warm up" time period as customers visits the pages. I there anyway to pre-warm up varnish/cache?
  3. Prices changes frequently everyday for a lot of products and it seems that I have to re-index (and clear cache + restarting varnish) often for those prices to be shown in the front-end. Problem is the prices index takes +45 minutes and apparently makes the front-end unavaliable. The question is if there are a better way to achieve the same result?

Best Answer

  1. You have to tell Magento where your Varnish instance is so that it can clear the cache. The dev docs have a section on this which you can see here - http://devdocs.magento.com/guides/v2.0/config-guide/varnish/use-varnish-cache.html

For example if varnish is running on 127.0.0.1:8080 you can run

bin/magento setup:config:set --http-cache-hosts 127.0.0.1:8080
  1. If you set up Magento to clear the Varnish cache above, it will only clear the cache for changed items (unless you flush everything which you should avoid if possible). You can use a tool like Siege to read your sitemap.xml if you want to build a little cache warming script.

  2. Magento 2 uses partial reindexing so it only reindexes changed items - this should also clear your full page cache when it completes. I believe there are some known issues with the price indexing in 2.2.

Related Topic