0

I have noticed by navigation doesn't seem to be being cached in static block cache and can see in profiler on each request showing like the below:

Magento_Theme/templates/html/topmenu.phtml  0.398847...

I want this to be cached to improve performance as have a fair few categories (thought it was cached by default). I have tried the below:

<referenceBlock name="catalog.topnav">
  <arguments>
    <argument name="cache_lifetime" xsi:type="number">65400</argument>
  </arguments> 
</referenceBlock>

I have also overriden the \Magento\Theme\Block\Html\Topmenu block and added:

protected function getCacheLifetime() {
  return 846000;
}

As well as attempting by adding the below within construct:

 $this->setCacheLifetime(846000);

By default the \Magento\Theme\Block\Html\Topmenu block has a cache lifetime set within the block and $this->getCacheLifetime() returns 846000.

To further debug I have also temporarily set $this->setCacheLifetime(846000); within Magento\Framework\View\Element\Template which then caches topmenu.phtml however the menu does not show and this also caches a lot of blocks that I do not want to cache. Unsure why setting in the actual block does nothing.

I am wondering what other reasons there are for why this block is not cached?

Your Answer

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

Browse other questions tagged or ask your own question.