0

I am using Varnish with Magento 2. I see that cache works (but for a short time) since I have the X cache: hit. And the TTFB is really good (40ms).

But I have *no-cache, must-revalidate, max-age=0* on the header for each page. My problem is that the varnish cache works for only a short time..

2

The value no-cache, must-revalidate, max-age=0 for Cache-Control that you see only applies to browser caches, which instructs Magento HTML to not be cached by them.

That Cache-Control that you're seeing is emitted by Varnish VCL. This is fine, and this value does not make Varnish cache less effective. This is only meant for browsers.

Varnish will use a different Cache-Control, emitted by Magento itself. Varnish cache lifetime depends on the TTL setting you have in Magento backend.

You can access Magento HTTP headers (by doing curl against the proper port) directly and you'll see that the Cache-Control emitted by it is different, typically one day:

Cache-Control: max-age=86400, public, s-maxage=86400. This is what Varnish sees and uses to define how long it caches public pages.

To recap:

  • Cache-Control: no-store, no-cache, must-revalidate, max-age=0 is to be expected unless you're checking Magento headers directly
  • To cache things longer by Varnish, adjust the TTL in Magento settings
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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