0

When I refresh page and check the header of homepage I got this below information where x-varnish-age=0 enter image description here Want to confirm if there is an issue with cacheable="false"? If any block on page is cacheable="false" so it causes x-varnish-age=0 for that page ? If yes if I have to make some block noncacheable, what should I do to make page varnish cacheable ?

asked Jan 21, 2022 at 2:37

2 Answers 2

1

I see that there's a Set-Cookie header in your response. That will cause Varnish to mark this incoming response as uncacheable because it changes the state.

If the next request for this resource doesn't return a response that contains the Set-Cookie header, you'll be fine and Varnish will store the object in the cache.

If every request returns a Set-Cookie header, the page will never end up in the cache.

As yourself why this cookie needs to be set and if this happens only once?

If you're looking for more information on Varnish and Magento, please have a look at the following article: https://www.varnish-software.com/developers/tutorials/configuring-varnish-magento/

answered Jan 21, 2022 at 7:50
0

The following function checks if a block is cacheable and is called for all blocks on page load. You can modify it (temporarily) to log the name in case of an uncacheable block:

vendor/magento/framework/View/Layout.php

 /**
 * Check existed non-cacheable layout elements.
 *
 * @return bool
 */
 public function isCacheable()
 {
 $this->build();
 $elements = $this->getXml()->xpath('//' . Element::TYPE_BLOCK . '[@cacheable="false"]');
 $cacheable = $this->cacheable;
 foreach ($elements as $element) {
 $blockName = $element->getBlockName();
 if ($blockName !== false && $this->structure->hasElement($blockName)) {
 $cacheable = false;
 //LOG $blockName
 break;
 }
 }
 return $cacheable;
 }

If the culprit does turn out to be an uncacheable block, you can goto the associated layout .xml file and make changes accordingly (if you are sure it won't affect the functionality of your app).

answered Sep 4, 2024 at 8:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.