I've a mega menu extension which I feel is quite slow. It seems to add about 2 seconds on load time for each page.

As this menu does not change between pages I was wondering how to cache a block? I want it generated just once on the first-page load after a cache flush so that each page can just load the cached block rather than having to repeat for each page on site.

The pages are cached and am not talking about the FPC here as page load is fine when cached but over 15,000 odd pages warming up a cache will save roughly 30,000 seconds if this is not repeated constantly.

  • Can i ask which megamenu extension it is as you will need to include caching in the extension Sep 19, 2017 at 13:57
  • Its called Ves MegaMenu i bought it from Landofcoder but comes up as from Venus Theme in admin.
    – harri
    Sep 19, 2017 at 14:04
  • You would need to get it rewritten to include caching i have a mega menu extension which i will be uploading publicly in the next few days i am just implementing caching Sep 19, 2017 at 14:08
  • Yeah i will take a look is it a free one? It seems to have suddenly sped up a bit but want it cached really am quite interested in rewriting it just never worked with the cache was hoping for a nudge in right direction.
    – harri
    Sep 19, 2017 at 14:12
  • Yes its free id suggest putting your site through cloud flair if your thinking about speed as this will cache your site with its inbuilt tools Sep 19, 2017 at 14:32

1 Answer 1


I think every block cache in magento,

But if you want to increase cachelifetime of particular block

You can do from your extension's block

go to your block and write below method

this method already there in Magento\Framework\View\Element\AbstractBlock

protected function getCacheLifetime()
    return 84600; // for one day you can increase or decrease this num as per your req

The cache lifetime can also be set like so within construct:

  • I'm not sure they are the profiler shows app/code/Ves/Megamenu/view/frontend/templates/topmenu.phtml 1.898545 for the time this goes up and down but surely would be quicker if this was cached?
    – harri
    Sep 19, 2017 at 14:19
  • in phtml do echo $block->getCacheLifetime() this will return false or some int value(if its cached) Sep 19, 2017 at 14:21
  • It didn't return anything in this case.
    – harri
    Sep 19, 2017 at 14:23
  • Means it return false create this method in your block and set time for caching Sep 19, 2017 at 14:25
  • It still shows false with getCacheLifetime set in block
    – harri
    Sep 19, 2017 at 14:29

Your Answer

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

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